One of my classes deals with HttpServletRequest and is a component like this:
@Component
public class AuthorizationService {
@Autowired
HttpServletRequest request;
public Boolean authorize(Integer fetId) {
...play with headers, db and other stuff...
}
and is used somewhere else like this
public class CarRestController {
@Autowired
CarService service;
@Autowired
AuthorizationService authorizer;
@RequestMapping(method = RequestMethod.GET)
public List<Car> get()throws Exception {
authorizer.authorize(666);
...
return cars;
}
My worry is that since AuthorizationService is a @component, it will be a singleton by default and therefore there can only be one request that will be swapped by newer ones coming as it is processed.
Should I do this to solve the problem?
@Component
@Scope("prototype")
public class AuthorizationService {
Many Thanks