Analysis and resolution of @ postconstruct exceptions executed many times in spring timing tasks

discover problems

A function has just been modified in the project recently. The code is preparing for verification. Start the debug mode of idea, run the project, find that the startup fails, check the log, and find that the scheduled task is repeatedly executed, resulting in an exception. Debug the initialization class of the scheduled task. It is found that the startup scheduled task is executed in the @ postconstruct method. Through online query, it is said that spring has a bug in initialization under certain circumstances, and the annotation @ component may be executed multiple times. Just change @ component to @ service!

As a result, I changed it and didn't solve the problem!

The rogue further followed up the log and found the following:

resolvent:

It turned out that there were a lot of scheduled task exceptions, so the initial exception content was ignored. The program was restarted after finding the exception, which was caused by the repeated @ requestmapping configuration in the gallerycontroller. Repeated @ requestmapping is not allowed in springmvc. The address in @ requestmapping is forgotten in the method just modified, so an error is reported. When idea finds an exception, it will automatically restart the Tomcat container. The result is an infinite loop. There are too many exception logs to see. The direction of exception troubleshooting is wrong!

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>