Note that the target servlet "myServlet" has not defined yet at this point. It is going to be defined later with
ServletRegistration.Dynamic servlet = servletContext.addServlet("myServlet" , myServlet.class);
When the web request is processed later, a NullPointerException may occur with similar stack:
java.lang.NullPointerException
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.getFilterChainContents(WebAppFilterManager.java:801)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.getFilterChain(WebAppFilterManager.java:357)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:957)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1131)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:5017)
...................
A workaround is to define the servlets prior to use it in the dynamic filter mappings. However, this rearrangement does not work when using with an embedded Spring Boot container which always invoke the filter operations before the servlet regardless the defined order in the application.
Application first adds a filter and maps it to a named servlet, for example:
FilterRegistration.Dynamic filter = servletContext.addFilter( "myFilter" , myFilter.class); filter.addMappingForServletNames(dispatcherTypes, true,"myServlet");
Note that the target servlet "myServlet" has not defined yet at this point. It is going to be defined later with ServletRegistration.Dynamic servlet = servletContext.addServlet("myServlet" , myServlet.class);
When the web request is processed later, a NullPointerException may occur with similar stack:
java.lang.NullPointerException at com.ibm.ws.webcontainer.filter.WebAppFilterManager.getFilterChainContents(WebAppFilterManager.java:801) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.getFilterChain(WebAppFilterManager.java:357) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:957) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1131) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:5017) ...................
A workaround is to define the servlets prior to use it in the dynamic filter mappings. However, this rearrangement does not work when using with an embedded Spring Boot container which always invoke the filter operations before the servlet regardless the defined order in the application.