I have a simple junit test class that use a simple bean service retrieved whether with @Autowired annotation or ctx.getBean() call.
In the second case I'm facing a LazyInitializationException when I try to read data from a lazy loaded collection. I assume this is because the session has been closed in the DAO service.
My question is, why I don't have this kind of trouble with the @Autowired way ?
Any idea ?Code:@ContextConfiguration(locations = { "classpath*:spring/applicationContext.xml" }) @RunWith(SpringJUnit4ClassRunner.class) @Transactional public class SimpleTest { @Autowired private IService service;//first scenario ok private IService service = ...getBean("myService");// second scenario ko @Test public void myTest() { MyObject myOo = service.retrieveMyObject("ref#1"); List list = myOo.getLazyCollectionOfSomething(); // ok with @Autowired service but LazyInitializationException with ...getBean() ... } }
I would be happy if I could understand :-)
Please feel free to answer me
Best Regards



Reply With Quote
