Lets say I have controller RequestController in Spring which is marked as Singleton. Inside this controller there is a biulder which is injected usinf dependency injection. The main goal for this class is to reveive requests and build responses.
@Singleton
class RequestController {
private ResponseBuilder responseBuilder;
private RequestController(ResponseBuilder responseBuilder){
this.responseBuilder=responseBuilder;
}
public Response getResponse(Request request) {
return responseBuilder.getRequest(request).build();
}
}
My question: What kind of pitfalls this code hide. What could go wrong when we try to use it in normal spring application. @Singleton is only an information that this class will be created only once per applications. I know that builder should be thread-safe since it will be responsible for handle multiple requests. But is anything else dangerous here?
Aucun commentaire:
Enregistrer un commentaire