I have a filter that extends OncePerRequestFilter
. When I the management.port=8081
and the server.port=8080
(or any differing ports), my filter is not called on any 8081 Urls.
The filter is only called on 8080 Urls.
How do I make it called on all Urls, including those on 8081?
Filter:
@Order( Ordered.LOWEST_PRECEDENCE )
public class TestFilter extends OncePerRequestFilter
{
public TestFilter()
{
System.out.println( "Started" );
}
@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException
{
System.out.println( "Checked should not filter" );
return false;
}
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException
{
System.out.println( "Filtering" );
// continue the processing
filterChain.doFilter( request, response );
}
}
I add it by:
@Configuration
public class MyConfig
{
@Bean
public TestFilter testFilter()
{
return new TestFilter()
}
}
EDIT:
I tried adding @ManagementContextConfiguration
to my config class, but this didn't work either.
Although I was unable to find documentation, it appears the answer is to do all of the following:
@ManagementContextConfiguration
META-INF/spring.factories:
before spring-boot-2.0.0.RELEASE:
org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=com.packageoutsidescan.MyManagementFilterConfigurationClass
after spring-boot-2.0.0.RELEASE (web
subpackage):
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=com.packageoutsidescan.MyManagementFilterConfigurationClass