简体   繁体   中英

Spring TransactionProxyFactoryBean honors transactions only when method is invoked from an external class

Here is a sample config that I'm using.

When i invoke the doSomething() method from an external class, the transactionality is as desired.

However, when i invoke the same method from within my "target" bean, it seems like the transaction never starts, so rollbacks don't occur in case of a failure.

Is that expected behavior or am i missing something?

<bean id="my.bean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="txManager"/>
    <property name="target" ref="my.bean.impl"/>
    <property name="transactionAttributes">
        <props>
            <prop key="doSomething">PROPAGATION_REQUIRED, -Exception</prop>
        </props>
    </property>
</bean>

Yes, it's an expected behavior. An interceptor or proxy wraps the target bean, intercepts calls made from the outside to the bean, and then delegates to the target bean. It doesn't know about internal calls. Byte-code instrumentation would be needed to intercept internal calls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM