Question

I'm trying to upgrade my project and so I've come to transactions. This is how I did it up to now.

<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>

I changed the transaction attributes like this bellow, but I'm not quite sure how could I link the service with exactly this txAdvice. Cause I generally have different transaction attributes for different services so there I guess should be more than one txAdvice. Is there a way how to say the @Transactional to use this particular txAdvice?

<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>
Was it helpful?

Solution

Alright, I figured out it.. it just came to me. Haha.. I just need to provide additional aop:advisor and aop:pointcut. As simple as that.

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top