我正在尝试向Filer
-
@Autowired
AuthRequestService authService;
并以doFiler
方法使用它-
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
System.out.println("SAPServiceFilter: "+ req.getRequestURI());
//TODO - create auth sender
authService.isAuthnticate((HttpServletRequest)request); //null
chain.doFilter(request, response);
}
我的@SpringBootApplication
类的子包中的过滤器类,并带有@service
-
@Service
public class AuthRequestService {
@PostConstruct
public void init() {
System.out.println("AuthRequestService @PostConstruct");
}
public boolean isAuthnticate(HttpServletRequest request) {
System.out.println("isAuthnticate");
return true;
}
}
使用-列出我所有的豆子时,该类也会出现
for (String name : applicationContext.getBeanDefinitionNames()) {
System.out.println(name);
}
在调试authService
为null时,仍然在FilterRegistrationBean
中注册了过滤器的最后一件事-
FilterRegistrationBean<SAPServiceFilter> filterRegBean = new FilterRegistrationBean<>();
filterRegBean.setFilter(new SAPServiceFilter());