一つは、HttpServletRequestを扱っそして、このようなコンポーネントです:Javaの春@ComponentスコープとHttpServletRequestの私のクラスの
@Component
public class AuthorizationService {
@Autowired
HttpServletRequest request;
public Boolean authorize(Integer fetId) {
...play with headers, db and other stuff...
}
と私の心配があることである。この
public class CarRestController {
@Autowired
CarService service;
@Autowired
AuthorizationService authorizer;
@RequestMapping(method = RequestMethod.GET)
public List<Car> get()throws Exception {
authorizer.authorize(666);
...
return cars;
}
のようにどこか別の場所で使用されて以来、 AuthorizationServiceは@componentであり、デフォルトではシングルトンになりますので、処理されるにつれて新しいリクエストにスワップされるリクエストは1つしかありません。
この問題を解決するにはどうすればよいですか? (それは、スプリングによって管理されますので)
@Component
@Scope("prototype")
public class AuthorizationService {
多くのおかげ
なぜそれを自動配線するのですか?それをメソッドに渡すと何が問題になりますか? –