Spring + Transaction = No transaction aspect-managed TransactionStatus in scope
Bonjour,
Nous implementons Spring (2.5) dans une application existante comportant hibernate 3.2. Nous avons des problemes avec la gestion de transaction.
Nous souhaitons passer les methodes de nos classes (existantes) dans un contexte transactionnel Spring.
Pour cela nous avons defini l'advice / pointcuts suivants :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<aop:aspectj-autoproxy/>
<!-- Test Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="mapGenTestTxAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<tx:method name="test*" propagation="REQUIRES_NEW" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="testTransactionPointcut" expression="execution(* com.mycompany.common.mapgen.*est*.*(..))" />
<aop:advisor advice-ref="mapGenTestTxAdvice" pointcut-ref="testTransactionPointcut" />
</aop:config> |
J'ai ajouté une petite methode de test pour valider que mon contexte transactionnel est bien ouvert :
Code:
1 2 3 4
|
public void testTransaction () {
TransactionStatus stat = TransactionAspectSupport.currentTransactionStatus();
} |
Malheureusement, comme le contexte de transaction n'est pas ouvert je prends une exception :
Code:
1 2 3 4 5
|
<error message="No transaction aspect-managed TransactionStatus in scope" type="org.springframework.transaction.NoTransactionException">org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope
at org.springframework.transaction.interceptor.TransactionAspectSupport.currentTransactionStatus(TransactionAspectSupport.java:109)
at com.mycompany.common.mapgen.BusinessKeysTest.testTransaction(BusinessKeysTest.java:54)
</error> |
Lorsque je trace le process Spring je vois bien les beans suivants créés (ApplicationContext.getBeanDefinitionNames retourne) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Creating application context with beans :
- [hibernateTemplate]
- [sessionFactory]
- [dataSourcePropertyConfigurer]
- [dataSource]
- [org.springframework.aop.config.internalAutoProxyCreator]
- [org.springframework.context.annotation.internalAutowiredAnnotationProcessor]
- [org.springframework.context.annotation.internalRequiredAnnotationProcessor]
- [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0]
- [org.springframework.transaction.interceptor.TransactionInterceptor#0]
- [org.springframework.transaction.config.internalTransactionAdvisor]
- [transactionManager] |
Je ne retrouve pas dans mes logs ni le AspectJAwareAdvisorAutoProxyCreator ni le JdkDynamicAopProxy ce qui m'amene à penser que j'ai un probleme de configuration de mon environnement aspect transaction. En revanche, j'ai un petit projet de test ou les transactions fonctionnent. Lorsque je trace, je retrouve bien ces composant dans les lignes de log :
Code:
1 2 3
|
[ Bankonet ] 14:07:58,052 [main] DEBUG org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator - Creating implicit proxy for bean 'clientDAO' with 0 common interceptors and 2 specific interceptors
[ Bankonet ] 14:07:58,052 [main] DEBUG org.springframework.aop.framework.JdkDynamicAopProxy - Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.bankonet.dao.hibernate.ClientDAOHibernate@16d3046] |
J'ai ensuite changé mon fusil d'épaule et décidé de tester en utilisant les annotations :
Code:
1 2 3 4 5
|
@Transactional (propagation=Propagation.REQUIRES_NEW)
public void testTransaction () {
TransactionStatus stat = TransactionAspectSupport.currentTransactionStatus();
} |
et le fichier de définition :
Code:
1 2 3 4 5 6 7 8 9
|
<aop:aspectj-autoproxy/>
<!-- Test Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<context:annotation-config />
<context:component-scan base-package="com.mycompany.common.mapgen" />
<tx:annotation-driven/> |
Sans plus de succès : meme erreur. Je suis donc un peu à court d'idée.
Merci de vos conseils pour resoudre ce probleme.