Comment faire en sorte que le service utilise un txadvice particulier au printemps?
-
13-11-2019 - |
Question
J'essaie de mettre à niveau mon projet et je suis donc venu à des transactions. C'est ainsi que je l'ai fait jusqu'à présent.
<bean id="userServiceTarget" class="com.forgin.service.UserServiceImpl">
<property name="userDAO" ref="userDAO" />
</bean>
<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="target" ref="userServiceTarget" />
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_SUPPORTS</prop>
<prop key="is*">PROPAGATION_SUPPORTS</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
J'ai changé les attributs de transaction comme ce ci-dessous, mais je ne sais pas trop comment pourrais lier le service avec exactement ce txAdvice
. Parce que j'ai généralement des attributs de transaction différents pour différents services, donc je suppose que je devrais y être plus txAdvice
. Existe-t-il un moyen de dire le @Transactional
Pour utiliser ce txadvice particulier?
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="is*" read-only="true" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
La solution
D'accord, je l'ai compris ... ça vient de moi. Haha .. j'ai juste besoin de fournir aop:advisor
et aop:pointcut
. Aussi simple que cela.
<aop:config>
<aop:pointcut id="userOperation"
expression="execution(* com.forgin.service.UserServiceImpl.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
<aop:pointcut id="differentOperation"
expression="execution(* com.forgin.service.DifferentServiceImpl.*(..))" />
<aop:advisor advice-ref="txAdviceDifferent" pointcut-ref="differentOperation" />
</aop:config>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow