2016-03-23 11 views
0

一つは、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 { 

多くのおかげ

+0

なぜそれを自動配線するのですか?それをメソッドに渡すと何が問題になりますか? –

答えて

0

春は、HttpServletRequestを自動的ようなリクエストスコープのオブジェクトの世話をします。 @Scopeを削除しても問題ありません。

関連する問題