Spring 事务 - 将 @Transactional 与混合到自定义注释中
我的目标是有某种方式将我的服务类声明为事务性的。我不想将其保留为 spring 配置中的显式声明。过去很多时候,我们创建了新服务,却忘记了围绕它们声明交易。因此,我的意图是,如果我有类似 @TransactionalService 自定义注释的内容,它应该执行以下操作:- 1.提供交易支持 2.声明一些Spring当前提供的事务支持的默认规则,如下所示。但与 spring 不同的是,我希望以下内容成为我的 @TransactionService 注释的一部分。
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
任何建议都会很有价值吗?
My goal is to have some way of declaring my service classes as transactional. I dont want to leave it as an explicit declaration in spring configuration. Many times in past we have created new services and forgot to declare transactions around them. Hence my intention is that if i have something like @TransactionalService custom annotation, it should do the following :-
1. provides transactional support
2. declares some default rules for transactional support as spring currently provides as shown below. But unlike spring, i would like the below to be part of my @TransactionService annotation.
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="get*" read-only="true"/>
<tx:method name="*"/>
Any advice would be valuable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您可以将事务服务放在同一个包中,而不是创建新的注释,然后您的切入点(所有事务服务只有一个切入点)将如下所示:
建议与上面相同:
Sure, instead of creating a new annotation, you could just put your transactionnal services in the same package, and then your pointcut (only one for all you transactionnal services) will look like this :
The advice is the same as above :