@EnableTransactionManagement,@ComponentScan and DataSourceTransactionManager problems

怎甘沉沦 提交于 2019-12-23 13:07:59

问题


In my application, I am using annotation-based spring configuration.

I was using @ComponentScan (and it worked fine). Now I'm trying to add simple transaction management using @EnableTransactionManagement.

However, when I add it, I start getting errors with one of the beans not being found (i.e. I get BeanCreationException because of NoSuchBeanDefinitionException). There is no other error (i.e. there is nothing related to the transaction management).

When I comment @EnableTransactionManagement out, everything works fine. I am trying to use this with a DataSourceTransactionManager

What could be the reason?


回答1:


One of the causes may be that your bean implements an interface.

When the bean implementing interface becomes @Transactional, a proxy should be created, as default it will be a JDK Proxy of the interface your class implements.

So because of the proxy, the bean now available only as interface(proxy) and not as the concrete class.

You should probably refactor your class - introduce another interface with service methods and reference it as interface and not as class.

See https://stackoverflow.com/a/8224772/241986



来源:https://stackoverflow.com/questions/18874912/enabletransactionmanagement-componentscan-and-datasourcetransactionmanager-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!