2012-09-27 23 views
1

當我將我的類打包到WEB-INF /類中時,我所擁有的Spring @Transactional方法(或任何匹配切點定義的方法)不參加交易。我遇到了很多'沒有發現Hibernate會話,配置不允許...'的日誌中的異常。令人費解的是,在堆棧跟蹤中,我可以看到CGLIB增強類,因此它看起來似乎被代理,但似乎沒有創建新的事務。Jetty 7中的WEB-INF/classes vs WEB-INF/lib

但是如果我打包同一類成一個jar文件,並把罐子放在WEB-INF/lib下,應用程序工作正常!交易創建等等,這裏發生了什麼?爲什麼當這些類在WEB-INF/classes下時它不工作?

Spring的事務配置如下:

<aop:aspectj-autoproxy proxy-target-class="true" /> 
<context:component-scan base-package="com.example" /> 
<tx:annotation-driven transaction-manager="txManager"/> 

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
</bean> 

<tx:advice id="serviceAdvice" transaction-manager="txManager">  
    <tx:attributes> 
     <tx:method name="save*"/> 
     <tx:method name="update*"/> 
     <tx:method name="delete*"/> 
     <tx:method name="*" read-only="true"/> 
    </tx:attributes> 
</tx:advice> 

<aop:config>   
    <aop:pointcut id="servicePointcut" expression="execution(* com.example.service.*.*Service*.*(..))"/>    
    <aop:advisor advice-ref="serviceAdvice" pointcut-ref="servicePointcut"/> 
</aop:config> 

FWIW,我使用碼頭7.4和Spring 3.1.2。

任何我應該找的線索?

更新:

啓用Spring的事務日誌,我可以看到:

28 Sep 2012 15:07:16,126 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [save*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] 
28 Sep 2012 15:07:16,133 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [update*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] 
28 Sep 2012 15:07:16,134 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [delete*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT] 
28 Sep 2012 15:07:16,136 DEBUG NameMatchTransactionAttributeSource:94 - Adding transactional method [*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly] 

但在時機成熟時,以實際的事務性方法工作,它與有關不例外爆炸允許創建交易。

回答

0
從它的外觀

無論是掃描該註釋只處理WEB-INF/classes目錄下的jar,而不是類

[編輯]碼頭未掃描這些註解

+0

感謝傑西!我知道Jetty並沒有掃描這些註釋,並且它的Spring角色可以在Web應用程序中執行,因此它應該被拾取。但在這一點上,我不知道在哪裏看,因此也拋出了Jetty標籤。 – calvinkrishy