Have a filter where a service is autowired. I am injecting the service as constructor argument - from the config where filter is registered.
MyFilter implements Filter {
private final ServiceToBeInjected serviceToBeInjected;
public MyFilter(ServiceToBeInjected serviceToBeInjected) {
this.serviceToBeInjected = serviceToBeInjected;
}
}
public class ConfigClass {
private final ServiceToBeInjected serviceToBeInjected;
@Autowired
public ConfigClass(ServiceToBeInjected serviceToBeInjected) {
this.serviceToBeInjected = serviceToBeInjected;
}
@Bean
public FilterRegistrationBean<MyFilter> filterRegistrationBean() {
final FilterRegistrationBean<MyFilter> filterRegBean = new FilterRegistrationBean<>();
filterRegBean.setFilter(new MyFilter(serviceToBeInjected));
filterRegBean.addUrlPatterns(");
return filterRegBean;
}
}
I kind of felt autowiring from config might not be good. Is there any other better way ?