In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "@ Scheduled does not implement how to do", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "@ Scheduled does not implement how to do" it!
@ Scheduled reason for not executing 1. Today I used @ Schedule to do a scheduled task.
I hope it will be executed at 1: 00 in the morning, with the following code
@ Servicepublic class ParseJsonService {@ Scheduled (cron = "0 01 * *?") Public void parseMongodbDataToJson () {}}
I came to the company the next day and found that it had not been implemented at all. And then start looking for problems.
two。 First came across a solution found.
It is said that it is the version of spring. I took a look at the scheduled tasks I used before. It is true that spring uses 4. 5%. So I changed the version of spring to 4 and found that it still didn't work.
3. There is also a version that says to be in spring.
Add an annotation driver to the configuration file of
And also add the default-lazy-init= "false" attribute, which says that spring is not allowed to load lazily, but it still doesn't work.
4. Also found that the version said to add @ Lazy (false) to Bean.
Let spring load the Bean at startup, but it still doesn't work.
The ultimate solution (for me, not necessarily for you, I use Spring version 3, not 4)
Step 1: add to the configuration file of spring
Step 2: add to the above Bean
@ EnableScheduling
The code is as follows:
@ Service@EnableSchedulingpublic class ParseJsonService {@ Scheduled (cron = "0 01 * *?") Public void parseMongodbDataToJson () {}} @ Scheduled invalid troubleshooting record @ Scheduled invalid troubleshooting record
The company before the project to add a regular processing, feel so easy.
@ Componentpublic class CommonSchedule {/ / @ Scheduled (cron = "0 01 * *?") @ Scheduled (cron = "* / 5 *?") Public void avg () {System.out.println ("the current time to start calculating the average is");}}
I thought it was done, but it didn't work!
Start searching for information online.
@ EnableScheduling also added no effect!
@ Lazy (false) is also added without effect!
Began to panic, read the package path is no problem ah, want to use xml to match again
It still doesn't work!
At this time, the front end visited my interface, looked at log, shit system printed!
Calm down for a while.
@ Lazy (false) does not work? It doesn't make sense, and then start to go through the configuration file to see if some bean add default-lazy-init= "true" attribute, and there is no ah.
Finally, it is found that:
I don't know which weird guy wrote off the business.
Decisively uncomment to solve the problem.
Thank you for reading, the above is the content of "@ Scheduled does not implement what to do". After the study of this article, I believe you have a deeper understanding of the problem of @ Scheduled not implementing how to do, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.