我的目标是通过某种方式将我的服务类声明为事务性的。我不想把它作为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="*"/>有什么有价值的建议吗?
发布于 2011-04-07 15:07:41
当然,您可以将您的事务服务放在同一个包中,而不是创建新的注释,然后您的切入点(所有事务服务只有一个)将如下所示:
<aop:config>
<aop:pointcut id="transactionnalServiceMethods" expression="execution(* x.y.transactionnalservice.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionnalServiceMethods"/>
</aop:config>建议和上面的一样:
<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="*"/>
</tx:attributes>
</tx:advice>https://stackoverflow.com/questions/2669329
复制相似问题