我有一个扩展OncePerRequestFilter
的过滤器。当我management.port=8081
和server.port=8080
(或任何不同的端口)时,我的过滤器不会在任何8081网址上调用。
在8080网址上调用过滤器 。
如何在所有网址上调用它,包括8081上的网址?
过滤器:
@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 );
}
}
我将其添加:
@Configuration
public class MyConfig
{
@Bean
public TestFilter testFilter()
{
return new TestFilter()
}
}
修改
我尝试将@ManagementContextConfiguration
添加到我的配置类中,但这也无效。
答案 0 :(得分:0)
虽然我无法找到文档,但似乎答案是所有以下内容:
@ManagementContextConfiguration
META-INF / spring.factories:
org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=com.packageoutsidescan.MyManagementFilterConfigurationClass