How to implement asynchronous processing according to the framework

There are many ways to achieve asynchronous implementation:
Insert image description herewe use the first method here

1. Add annotations.
Add the @EnableCustomConfig annotation in the springboot config to enable the asynchronous thread function
Insert image description here. 2. Create the asynchronous method Service and implementation class.
I am too lazy to write the interface here. I can just add it to the configuration file after testing
Insert image description hereInsert image description here, otherwise it will prompt that it cannot be found. bean

3. Call the asynchronous method and check the test results.
I can just find a controller here and test it.
Insert image description hereThe result:
Insert image description herecall the interface and postman will directly return to
Insert image description herethe background printing at this time.

Insert image description herePrint after 10 seconds

Insert image description here

Guess you like

Origin blog.csdn.net/qq_40579139/article/details/125780865