May 1st, 2011, 02:29 PM
Autowiring works in unit tests but not on server
This is kind of an abstract question.
I am maintaining some code that has been hacked together with bits of Spring via annotations.
I was able to unit test some of my Dao code by getting the class from the application context, but when i run it on the server im getting null pointers all over.
The best part is, when the application starts up the beans get created, i have a log message in one of the Autowire setter methods that's firing.
Now i was able to bypass this by making the needed attribute static, and in the methods manually building the objects.
My question is, does this sound like a moderately common problem?
All that i've been finding on the web were things like forgetting either
<context:annotation-config /> or
which are in my applicationContext
May 2nd, 2011, 01:09 AM
Common problems are, creating the object twice (multiple component-scan elements), creating instances yourself instead of getting them from the applicationcontext. IN general it is configuration. So post your configuration (including web.xml) using [ code][/code ] tags !!! (that way it remains readable)...