所以在最新版本的 Spring 中,我们可以使用 @Configuration
注释来设置 Spring 的配置。现在在 JavaConfig 中,可以使用 @AnnotationDrivenTx
(@AnnotationDrivenTx Reference Link) 注释在我们的 Config 类中设置事务。但是由于 JavaConfig 已经退役,我想知道是否有人知道如何在没有 JavaConfig 的情况下设置类似的东西并且不需要向 application-context.xml
添加任何内容。这就是我的 Config 类的基本内容
@Configuration
@ImportResource("config/application-context.xml")
public class Config {
public @Bean DataSource dataSource() {
//get and return datasource
}
public @Bean Service1 getService1() {
//return service1Impl
}
}
我想让 Service1
成为事务性的。如果有人对如何做到这一点有任何想法,或者如果这是不可能的,请告诉我。
谢谢!
最佳答案
您现在可以使用 @EnableTransactionManagement
。
查看这篇文章了解更多详情:http://blog.springsource.com/2011/06/10/spring-3-1-m2-configuration-enhancements/
https://stackoverflow.com/questions/3722310/