在 Spring 中的 @Configuration 类中设置注解驱动的事务
因此,在最新版本的 Spring 中,我们可以使用 @Configuration 注解来设置 Spring 的配置。现在在 JavaConfig 中可以使用 @AnnotationDrivenTx
(@AnnotationDrivenTx 参考链接) 注释,用于在我们的 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
具有事务性。如果有人对如何执行此操作有任何想法,或者如果这是不可能的,请告诉我。
谢谢!
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
}
}
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.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您现在可以使用
@EnableTransactionManagement
。有关更多详细信息,请参阅此帖子: http:// /blog.springsource.com/2011/06/10/spring-3-1-m2-configuration-enhancements/
You can now use
@EnableTransactionManagement
.See this post for more details: http://blog.springsource.com/2011/06/10/spring-3-1-m2-configuration-enhancements/
根据 此论坛帖子,这似乎是不可能的:
等等:但你似乎还是有一个 XML 上下文。为什么不添加
并使用@Transactional
?It seems like it isn't possible according to this forum post:
Wait: but you seem to have an XML context anyway. Why not add
<tx:annotation-driven/>
to it and use@Transactional
?看看 http://blog.springsource.com /2011/02/17/spring-3-1-m1-featurespec。 Spring 3.1的FeatureSpecification类(例如TxAnnotationDriven)旨在准确解决上述问题。
Take a look at http://blog.springsource.com/2011/02/17/spring-3-1-m1-featurespec. Spring 3.1's FeatureSpecification classes such as TxAnnotationDriven are designed to solve exactly the problem described above.