Junior — Middle
What level of visibility scope should be specified for the controller to be able to track the execution of requests?
sobes.tech AI
Answer from AI
For a controller that needs to track the execution of requests, the Request Scope is usually used.
This means that an instance of the controller is created for each HTTP request and destroyed after its processing. This approach allows storing state related to a specific request and tracking its execution.
In Spring, for example, this is achieved with the annotation:
@Controller
@Scope("request")
public class MyController {
// fields and methods
}
If the scope is not specified, controllers are usually singletons by default, which is not suitable for tracking the state of a specific request.