I want to access a spring component from OncePerRequestFilter class, but I am getting null pointer when I access service, and I think the reason for that is the configuration. I think the filter is getting called before the spring dispatcher servlet due to the configuration. Any good way to get this done, suggestions please.
<servlet>
<servlet-name>SpringDispatcherServer</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/springConfig.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringDispatcherServer</servlet-name>
<url-pattern>/test/api/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>AuthCheck</filter-name>
<filter-class>org.test.util.AuthCheckFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthCheck</filter-name>
<url-pattern>/test/api/*</url-pattern>
</filter-mapping>`
public class AuthCheckFilter extends OncePerRequestFilter
{
@Autowired
private AuthCheckService authCheckService;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
log.info("authCheckService"+authCheckService);
and the logger prints null for "authCheckService"