[Java] [Spring] Spring transaction does not work problem rollup

Source: Internet
Author: User

Recently encountered in the project when the Pring transaction does not work, and later resolved, here I summarize:

1, first use the following code to confirm that your bean is the proxy object?

A transaction must be a bean that is defined by the spring (either through XML or annotation definitions).

Adding transactions directly to new objects is not working.

You can determine whether a proxy object is in the following ways:

Aoputils.isaopproxy (Object object)

Aoputils.iscglibproxy (Object Object)//cglib

Aoputils.isjdkdynamicproxy (Object Object)//jdk dynamic Proxy


2. The entry function must be public, otherwise the transaction will not work. This is determined by spring's AOP characteristics.


3, pointcut configuration error.

<!--configure transactions using annotation annotations--
<tx:annotation-driven transaction-manager= "TransactionManager" proxy-target-class= "true"/>

<!--Configure transactions using facets---
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "*" isolation= "read_committed" propagation= "REQUIRED" rollback-for= "Java.lang.Exception"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id= "pointcut" expression= "Execution (* com.tyyd). *service.do* (..)) " />
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "Pointcut"/>
</aop:config>


4. If you use SPRINGMVC, it may be caused by a context:component-scan repeat scan:


5, such as the use of MySQL and the engine is MyISAM caused (because the transaction is not supported), InnoDB can be changed.


[Java] [Spring] Spring transaction does not work problem rollup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.