如何解决将 servlet 过滤器注入 spring 管理的上下文
我正在使用一个外部 jar,其中有一个非 spring 管理的 servlet 过滤器。我的应用程序建立在 spring boot 上如何将 servlet filter(TestHeaderFilter) 注册到 spring boot context,以便在发生任何 http 调用时可以拦截它。我的 Spring Boot 应用程序中有两个过滤器,一个是使用 Spring WebFilter,它当前正在拦截调用,但另一个过滤器(jar 内的 Servlet 过滤器)尝试通过 FilterRegistrationBean 注册没有拦截调用我如何注册这个 servlet 过滤器以便它在 IdentityFilter
之前拦截调用在 jar 中的类不能修改,这个类中使用的依赖用@component 注释,所以依赖是 spring 管理的
var ent = document.querySelector('#model3D');
if(voiceCommand.includes("hello")) {
ent.setAttribute("animation",'property: rotation; to: 0 360 0; loop: false; dur: 5000');
}
我尝试通过 FilterRegistrationBean 注册 (TestHeaderFilter) 但似乎不起作用的类
@Slf4j
@Order
@AllArgsConstructor
public class TestHeaderFilter implements Filter {
private IdGenerator idGnerator;
private IdSpanGenerator idSpanGenerator;
@Override
public void init(FilterConfig filterConfig) throws servletexception {
}
@Override
public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain chain)
throws IOException,servletexception {
chain.doFilter(modifiedRequest,response);
}
@Override
public void destroy() {
}
}
@Configuration
public class TelemetryConfig {
private IdGenerator idGnerator;
private IdSpanGenerator idSpanGenerator;
@Bean("idGnerator")
@Lazy
@Primary
public IdGenerator idGnerator(){
return new IdGenerator();
}
@Bean("idSpanGenerator")
@Lazy
@Primary
public IdSpanGenerator idSpanGenerator(){
return new IdSpanGenerator();
}
@Bean
public FilterRegistrationBean<TestHeaderFilter> traceIdHeaderFilterRegistrationBean() {
FilterRegistrationBean<TestHeaderFilter > registrationBean
= new FilterRegistrationBean<>();
registrationBean
.setFilter(new TestHeaderFilter(idGnerato(),idSpanGenerator()));
registrationBean.setorder(-1);
registrationBean.addUrlPatterns("/");
return registrationBean;
}
}
解决方法
您的过滤器注册 (registrationBean.addUrlPatterns("/");
) 的 URL 模式意味着过滤器将仅针对对 /
的请求调用,而不会针对其他任何请求调用。您可能想改用 /*
。
/*
是默认值,因此您应该能够通过删除添加 url 模式的行来解决您的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。