我只是听不懂.是否通过@Transaction批注将@Serviced标记为@Serviced并在@ContextComponent中在应用程序上下文中注册的bean,以提供事务支持?
这工作正常:
public class LocationManagerImpl implements LocationManager {
@Transactional
public void saveLocation(Location location) {
}
}
//config class
@Bean
public LocationManager locationManager() {
return new LocationManagerImpl();
}
这不是:
@Service
public class LocationManagerImpl implements LocationManager {
@Transactional
public void saveLocation(Location location) {
}
}
最佳答案
问题可能是您的@Transactional带注释的类位于servlet上下文中.如果您具有< context:component-scan>在servlet应用程序上下文配置中,而Spring AOP拦截器在根应用程序上下文中配置.
原文链接:https://www.f2er.com/spring/531826.html解决方案是将带@Service注释的类移至根Web应用程序应用程序上下文.
参见Spring @Transactional not working.
Servlet和Web App Root上下文之间的区别:
Difference between applicationContext.xml and spring-servlet.xml in Spring Framework.