Como fazer o serviço usar txAdvice específico no Spring?
-
13-11-2019 - |
Pergunta
Estou tentando atualizar meu projeto e então cheguei às transações.Foi assim que fiz até agora.
<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>
Alterei os atributos da transação assim abaixo, mas não tenho certeza de como vincular o serviço exatamente a isso txAdvice
.Porque geralmente tenho atributos de transação diferentes para serviços diferentes, então acho que deveria haver mais de um txAdvice
.Existe uma maneira de dizer o @Transactional
usar este txAdvice específico?
<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>
Solução
Tudo bem, eu descobri..simplesmente veio até mim.Haha..Eu só preciso fornecer informações adicionais aop:advisor
e aop:pointcut
.Tão simples como isso.
<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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow