Bernie's Blog A confusing concoction of Java, mobile devices, technology and photography

25Nov/090

Dependency Injection Fails With Spring 3.0.0 RC2, JUnit 4.7, Mockito

Following text-book examples of using SpringJUnit4ClassRunner.class with Mockito, I couldn't get DI to work. It doesn't matter if I use the old-school way of XML configuration + setter injection or if I use annotations, they just don't work. Oddly though, the log shows that the application context did start, and beans were instantiated, they were just not injected and the beans are null. The beans are not mocks, but real classes that I need to use.

Curious, I created a simple main method to test the program and true enough, things work. As of now, I'm unable to determine why this is failing and I'm already delayed, so I'm abandoning Spring 3.0 for now. JUnit and Mockito works as I've only recently added Spring to get some AOP stuff working.

If you've got a similar combination working, I'm interested to know how this was done. Oddly enough, I can't seem to Google for any similar problems.