In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what to do if @ Async cannot be asynchronized in Spring. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Spring @ Async cannot implement the cause of asynchronous problem
There are two configuration files in the project: springMVC.xml and beanDefines.xml, both of which are configured.
It is also configured in beanDefines.xml.
From the startup log, it is found that spring loads beanDefines.xml first and then springMVC.xml.
Because the context:component-scan of springMVC.xml overrides the configuration of beanDefines.xml, whether it is effective depends on the configuration of context:component-scan.
Causes the beanDefines.xml configuration not to work.
Solution.
1. Delete the sum of beanDefines.xml
2. Add configuration to springMVC.xml.
@ Async does not work
Let's first introduce how to @ Async annotations.
The 1.xml header file must be configured with the marked red part
two。 Configure task and thread pool 3. Configure the jar that spring depends on (not to cover this) 4. Use @ Async annotations on methods that you need to call asynchronously
5. But you may encounter a time when @ Async doesn't work.
My problem is that the container startup loads the following two xml files
The springmvc.xml file only configures scan annotations, while applicationContext.xml configures tasks and thread pools and scan annotations, loading applicationContext.xml first and then springMvc.xml.
ApplicationContext.xml adds @ Async to the scanned class (the configuration of the task and thread pool depends on the scanned class), and then the bean loaded by springMvc overrides applicationContext's bean, overriding the role of @ Async, because springmvc does not configure task and thread pool
As a result, @ Async does not work.
This is the end of the article on "what if @ Async cannot be asynchronous in Spring". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.