In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to solve the problem that transaction control is configured in SSM but does not take effect". In daily operation, I believe that many people have doubts about how to solve the problem when configuring transaction control in SSM. Xiaobian consulted all kinds of data and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubt that "transaction control has been configured in SSM but does not take effect." Next, please follow the editor to study!
SSM configured transaction control but did not take effect
Today, when using ssm transactions, I found that the method reported an error, and the transaction was not rolled back. After a long time, it was finally solved. I am using programmatic transactions, even in the way of configuration files, for the record below.
Package structure, the following is the springmvc.xml configuration file
Spring profile: applicationContext.xml
First of all, we make it clear that when spring carries out scanning and injection, because the context of spring is a parent-child container, and the ContextLoaderListener listener loads the spring configuration file, the parent container is generated, and the mvc loads the configuration file of mvc, resulting in a child container. When the child container scans @ Controller, it also assembles the @ Service annotation instance, because the @ Contoller instance depends on the @ Service instance, and the @ Service instance is in the child container. When we use mvc S or C Service S to operate on the database, if there are @ Service instances in the child container, the @ Service instance in the child container is preferred, but the instance annotated by @ Service, that is, the general transaction control layer, should be initialized by the parent container to ensure enhanced transaction processing, otherwise it will lose its transaction processing capacity.
So we want to ensure that there are no instances of @ Service annotations in the subcontainers.
My mistakes.
So there are the two scans above, but there is something wrong with my springmvc.xml configuration file, and I don't understand what context:include-filter means.
To put it more popularly:
Context:exclude-filter is setting the blacklist. For example, the mobile phone blacklist, the people in the blacklist can not make phone calls.
Context:include-filter is set whitelist. Numbers in the mobile phone whitelist can be called in, and those that are not in the whitelist or blacklist can also be called in. So you need to set it up for whitelist filtering, turn off the default filter and use use-default-filters= "false"; then he just scans the specified comments.
This is fine, of course, since the examples of my @ Contoller annotations are all in the com.djw.controller package, I can also do the following
Several reasons why SSM transaction configuration does not work and does not roll back
I was a rookie. I didn't learn well before, so I didn't do much research when I was working on the project. Now the project is almost finished, and I want to add the transaction to it, but it doesn't work all the time. Finally, I got it (copied).
Summarize several reasons for the failure of my transaction configuration.
When 1.@Transactional uses this annotation, I just add it directly to the class. Later, I find that there is something missing. I should write @ Transactional (rollbackFor = Exception.class) like this.
two。
The comment scan component-scan was put in the wrong place. It was put in the spring-mvc before. Later, I saw that other people's blogs said it was going to be put in the spring-mybatis, so I put it there, but it was still useless. Later, I found that there was a comment scan component-scan in the spring-mvc, and then deleted this, and the note worked perfectly.
Here is the code for basic use
Spring-mybatis:
ServiceImpl:
@ Service@Transactional (rollbackFor = Exception.class) public class TestServiceImpl implements ITestService {@ Override public void del (int id) throws Exception {address.delete (aid); int iSuppli 1Universe 0;} at this point, the study of "transaction control is configured in SSM but does not take effect" is over. I hope to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.