Home > Java > javaTutorial > body text

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

不言
Release: 2018-10-10 11:37:50
forward
1984 people have browsed it

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" />
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!