File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Why is autowiring working in JUnit test but not in bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Why is autowiring working in JUnit test but not in bean?" Watch "Why is autowiring working in JUnit test but not in bean?" New topic
Author

Why is autowiring working in JUnit test but not in bean?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using Spring 3.0.5. I'm running a JUnit test to test db connectivity. I have



and when I run the JUnit test, the "sessionFactory" is configured fine. However, another class that is invoked in the JUnit test has an identical "sessionFactory" reference, which remains null ...



This doesn't happen when I run the real application. Any ideas why one autowiring is working and the other isn't connecting at all? When I run my application outside of the JUnit environment, the autowiring within the "WebLeadsDAOImpl" class gets connected just fine.

Thanks, - Dave
Boris Romashov
Ranch Hand

Joined: Feb 23, 2009
Posts: 38
Why in WebLeadsDAOImpl the field SessionFactory is static?
Try to make it an instance-method.
 
jQuery in Action, 2nd edition
 
subject: Why is autowiring working in JUnit test but not in bean?
 
Similar Threads
ejb-spring-hibernate
how to map multiple url patterns using spring annotations
Hard time getting Spring working with WS'.
Dependency injection problem
@Autowired not working in JUnit using spring 2.5