Home  >  Article  >  Java  >  Solution to the problem that transactions cannot be managed by spring container

Solution to the problem that transactions cannot be managed by spring container

不言
不言forward
2018-10-10 11:37:511939browse

This article brings you the solution to the problem that transactions cannot be managed by the spring container. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

I am currently working on a small project using the springmvc mybatis framework. Every time there is a JDBC Connection [com.mysql.jdbc.JDBC4Connection@59dfe4bc] output in the console log

It shows that there must be a problem with the transaction configuration. I went to look at the configuration file and found that the annotated transaction was configured. I looked at the code and also used the @Transactional annotation.

So I started thinking about what went wrong. Because I had seen some source code of spring and some source code of springmvc before, I had some ideas. After some thinking, I located the problem to the spring configuration file

and springmvc configuration file

After adding the transaction annotation to the scanned bean in the spring configuration file, spring will add a proxy to it with transaction capabilities. After the springmvc container is started, it has a parent-child relationship with the spring container, getbean The process is to first fetch the

bean of the sub-container. The problem lies here. The beans in the springmvc container do not have transaction processing capabilities, so I made some adjustments to the scanning strategy.

In the springmvc configuration file Add

<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />

to the annotation scan and run the project

spring to manage the transaction.

The above is the detailed content of Solution to the problem that transactions cannot be managed by spring container. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete