When we use XmlBeanFactory, TX annotation is not working. and it does not even load when you say
So if you want to use annotation, please use ClassPathXmlApplicationContext. I believe in WEB application, tomcat system actually uses ClassPathXmlApplicationContext. So in order to make your code testing separately, please do not use XmlBeanFactory.
Below it is the example of XmlBeanFactory and ClassPathXmlApplicationContext
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(
"applicationContext2.xml"));
InvoiceProcessDao process = (InvoiceProcessDao)factory.getBean("invoiceProcess");
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext3.xml");
InvoiceProcessDao process = (InvoiceProcessDao)ctx.getBean("invoiceProcess");
process.checkPayment();
System.out.println(" Over") ;
This is correct. I too had faced problem with @@Transactional when using XmlBeanFactory to load the beans. Thanks for posting this. I wish i would have found this a few days back...
ReplyDeleteThanks for sharing...
ReplyDeleteBut rather than saying TX annotation is not working. and it does not even load when you say in XML file.
You could have said more clearly like the person has commented above @@Transactional...
Because many ppl like me do not know what is TX annotation...