在@Configuration类中设置在Spring中注释驱动的事务 [英] Setting Up Annotation Driven Transactions in Spring in @Configuration Class

查看:719
本文介绍了在@Configuration类中设置在Spring中注释驱动的事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在最新版本的Spring中,我们可以使用 @Configuration 注释来设置Spring的配置。现在在JavaConfig中可以使用 @AnnotationDrivenTx @ AnnotationDrivenTx Reference Link)注释以在Config类中设置事务。但是,由于JavaConfig已经停用,我想知道是否有人知道如何设置类似没有JavaConfig,而不需要添加任何东西到 application-context.xml 。这是我基本上为我的配置类

So in the latest version of Spring we are able to use the @Configuration annotation to setup our configurations for Spring. Now in JavaConfig it is possible to use the @AnnotationDrivenTx (@AnnotationDrivenTx Reference Link) annotation to setup transactions in our Config class. But since JavaConfig has been decommissioned I was wondering if anyone knew how to setup something similar without JavaConfig and without needing to add anything to the application-context.xml. Here is what I basically have for my Config class

@Configuration
@ImportResource("config/application-context.xml")
public class Config {

     public @Bean DataSource dataSource() {
           //get and return datasource
     }

     public @Bean Service1 getService1() {
          //return service1Impl
     }
}

我想让 Service1 交易。如果任何人有任何想法如何做到这一点,或者如果这只是不可能,请让我知道。

And I'd like to make Service1 transactional. If anyone has any ideas on how to do this or if this is just not possible please let me know.

谢谢!

推荐答案

c> @EnableTransactionManagement 。

You can now use @EnableTransactionManagement.

有关详情,请参阅此文章:http://blog.springsource.com/2011/06/10/spring-3-1-m2-configuration-enhancements/

See this post for more details: http://blog.springsource.com/2011/06/10/spring-3-1-m2-configuration-enhancements/

这篇关于在@Configuration类中设置在Spring中注释驱动的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆