I'm using @Transactional and transaction management by annotation (tx:annotation-driven...). I have problem when I'm using GenericApplicationContext to create application context and get some beans from it:
GenericApplicationContext ctx = new GenericApplicationContext();
// Load beans definitions
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions(new ClassPathResource(CONTEXT_PATH));
// Register the datasource
ctx.getBeanFactory().registerSingleton(CONTEXT_DATASOURCE_BEAN_NAME, dataSource);
// Get the service
ServiceInterface service = (ServiceInterface) ctx.getBean("service");
I've got the instance of ServiceInterface but I want to have the proxy which contains information about transactions.
Could you explain me what I've missed?
There is need to call ctx.refresh() before ctx.getBean(). Then the BeanPostProcessors will be invoked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.