[英]How make OncePerRequestFilter called when management.port is different from server port?
I have a filter that extends OncePerRequestFilter
.我有一个扩展
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.当我使用
management.port=8081
和server.port=8080
(或任何不同的端口)时,不会在任何 8081 Urls 上调用我的过滤器。
The filter is only called on 8080 Urls.过滤器仅在 8080 Urls 上调用。
How do I make it called on all Urls, including those on 8081?我如何让它在所有 URL 上调用,包括 8081 上的 URL?
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.编辑:我尝试将
@ManagementContextConfiguration
添加到我的配置类,但这也不起作用。
Although I was unable to find documentation, it appears the answer is to do all of the following:虽然我找不到文档,但似乎答案是执行以下所有操作:
@ManagementContextConfiguration
@ManagementContextConfiguration
注释的类 META-INF/spring.factories: META-INF/spring.factories:
before spring-boot-2.0.0.RELEASE:在 spring-boot-2.0.0.RELEASE 之前:
org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=com.packageoutsidescan.MyManagementFilterConfigurationClass
after spring-boot-2.0.0.RELEASE ( web
subpackage):在 spring-boot-2.0.0.RELEASE (
web
子包) 之后:
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=com.packageoutsidescan.MyManagementFilterConfigurationClass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.