Spring boot- inject service into doFiler

后端 未结 2 984
挽巷
挽巷 2021-01-26 12:55

I am trying to inject a auth service to a Filter -

@Autowired
AuthRequestService authService;

And use it in doFiler

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-26 13:15

    You could use constructor injection. Supposed your filter registration bean lives in a component and has access to the service you could autowire it there and pass it with the constructor

    @Autowired  
    AuthRequestService authRequestService;
    
    [...]
    
    FilterRegistrationBean filterRegBean = new FilterRegistrationBean<>();
    filterRegBean.setFilter(new SAPServiceFilter(authRequestService));
    

提交回复
热议问题