Spring self injection for transactions

假装没事ソ 提交于 2019-12-08 15:46:41

问题


In Spring you can't simply call @Transactional method from the same instance, because of AOP-proxy thing. Would it be nice idea to make a self injection and call that method from self proxy instance? Do you see any drawbacks?


回答1:


It is totally ok. Moreover there was a Jira ticket for supporting this feature using @Autowired annotations. It's fixed in Spring 4.3+ versions. However for xml-based configuration or using @Resource annotation it's working in the earlier versions.

You can see the discussion bellow this ticket. @Transactional is one of the use case for this:

Particularly interested in @Async and @Transactional use cases.



来源:https://stackoverflow.com/questions/43280460/spring-self-injection-for-transactions

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