Reputation: 584
I have a servlet that gets some parameters and from those I construct another object(responseObject). This response object is accessed in a lot of classes elsewhere so it needs to be autowired in those classes.
The other classes can add content into the responseObject(essentially modify the object).
So summing up the desired features are :
I am wondering if such a thing is possible in Spring.
I tried prototype and request scopes but I ran into errors. The main issue is that the object needs to be modified by other classes and needs to have those changes while the request is still being served.
Upvotes: 1
Views: 231
Reputation: 19987
This is not what autowiring is used for. What you want to do is simply pass the response object to the classes/methods that need it.
A word of advise: It is better to not let request and response objects wander too much through your codebase. You want to limit their use as much as possible to the places where they are actually needed (i.e. servlets). The servlet may need some data from several places to produce a reponse. That's fine. Get the data and produce the response. It is better to pass the data to where the response is than to pass the reponse to where the data is. Same for the request object, but the other way around. The underlying principle is that it is usually best to decouple input from output.
Upvotes: 1