Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why in WebLeadsDAOImpl the field SessionFactory is static?
Try to make it an instance-method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic