2010-04-19 5 views
1

내 목표는 서비스 클래스를 트랜잭션으로 선언 할 수있는 방법입니다. 스프링 구성에서 명시 적 선언으로 남기고 싶지 않습니다. 과거에는 여러 번 새로운 서비스를 만들었고 그 주위에 거래를 선언하는 것을 잊어 버렸습니다. 그러므로 내 의도는 @TransactionalService 커스텀 어노테이션과 같은 것이 있다면 다음과 같이 처리해야한다는 것이다. - 1. 트랜잭션 지원을 제공한다. 2. 스프링이 현재 아래와 같이 제공하고있는 트랜잭션 지원을위한 기본 규칙을 선언한다. 하지만 봄철과는 달리 아래의 내용은 @TransactionService 주석의 일부가되고 싶습니다.Spring 트랜잭션 - @Transactional과 <tx:advice>을 맞춤 주석으로 섞음

<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="*"/> 

어떤 조언은 도움이 될 것인가?

답변

0

물론 대신 새로운 주석을 작성, 당신은 그냥 다음과 같을 것이다 다음 포인트 컷 (모든 당신 transactionnal 서비스에 대해 하나)를 동일한 패키지에 transactionnal 서비스를 넣어 수 :

<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>