I have been writing a Spring Boot application for the last few months. The user enters 2-3 pieces of information in an interface, presses “Start” and the app now runs for 2-3 minutes (which was okay for the business, because it’s was easier to implement) and collects hundreds of pieces of information from various systems. Because this can be done by several users at the same time, we have assigned the scope “Request” to almost every class. The users can no longer act on the result displayed.
Now there is suddenly the requirement that the user should only press the button, he immediately receives a confirmation that the request has arrived, and the rest should run completely async. The results are then stored on a file server via FTP. The user will collect the file 1-2 hours later.. The first solution should remain. I never done any async stuff in java.
Now I have added the @async
to one central methods and receive the following message when starting: Scope 'request' is not active for the current thread
Is there a simple, good way to activate the request scope for Async? Or does this have too many disadvantages? If I had known the requirement from the beginning, what would have been the right way to set it up accordingly?
The structure currently looks something like this:
My Main Class is the RestController
-class which will handle the request.
This class is calling the DataCollector
-class. This DataCollector
class will then use different client
-classes (like SAPClient
, BWClient
, R45Client
etc.) to speak to the different systems and collect some data. All the selected data is collected in a central model called CentralDataModel
which is used basiclly in all classes, because we need to exchange some data for some requests… and end the end, we are creating a pdf.
If these data dependencies weren’t there, I might be able to build the whole thing differently, but unfortunately we have them now.
Do I now have to remove all DI mechanisms, mark the data collector as a “prototype” and “hardwire” the model to the client so that I am sure that I am not distributing any “foreign” data?