在Spring注释配置中使用@Service与@Service进行交互

在Spring注释配置中使用@Service与@Service进行交互,第1张

概述我只是听不懂.是否通过@Transaction批注将@Serviced标记为@Serviced并在@ContextComponent中在应用程序上下文中注册的bean,以提供事务支持?这工作正常: public class LocationManagerImpl implements LocationManager { @Transa

我只是听不懂.是否通过@Transaction批注将@Serviced标记为@Serviced并在@ContextComponent中在应用程序上下文中注册的bean,以提供事务支持?

这工作正常:

    public class LocationManagerImpl implements LocationManager {        @Transactional        public voID saveLocation(Location location) {        }    }//config class@Beanpublic LocationManager locationManager() {    return new LocationManagerImpl();}

这不是:

@Servicepublic class LocationManagerImpl implements LocationManager {    @Transactional    public voID saveLocation(Location location) {    }}
最佳答案问题可能是您的@Transactional带注释的类位于servlet上下文中.如果您具有< context:component-scan>在servlet应用程序上下文配置中,而Spring AOP拦截器在根应用程序上下文中配置.

解决方案是将带@Service注释的类移至根Web应用程序应用程序上下文.

参见Spring @Transactional not working.

Servlet和Web App Root上下文之间的区别:
Difference between applicationContext.xml and spring-servlet.xml in Spring Framework. 总结

以上是内存溢出为你收集整理的在Spring注释配置中使用@Service与@Service进行交互 全部内容,希望文章能够帮你解决在Spring注释配置中使用@Service与@Service进行交互 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1237202.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存