2010-04-21 43 views
0

有沒有辦法讓bean在春季框架中不可用?我想確保如果開發人員忘記在Spring框架中圍繞服務包裝事務,那麼該服務在運行時應該變得不可用。 謝謝,防止忘記在春季配置事務

+0

你必須標記一些你接受的問題的答案(通過投票櫃檯下面的勾號) – Bozho 2010-04-21 19:03:39

回答

1

你可以用AOP做這樣的事情。但是相反,你可以添加自動交易的每一個服務方法與AOP:

<!-- proxy-target-class should be true, if you don't use interfaces --> 
<aop:config proxy-target-class="false"> 
    <aop:pointcut id="serviceMethods" 
     expression="execution(* com.yourproject.services..*.*(..))" /> 

    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" /> 
</aop:config> 

<tx:advice id="txAdvice" transaction-manager="yourTransactionManager"> 
    <tx:attributes> 
     <tx:method name="*" propagation="REQUIRED" /> 
    </tx:attributes> 
</tx:advice> 

您可以通過使用@Transactional覆蓋這些默認設置。但是,建議優先級不直截了當。有關它的檢查this article