<i id='xuR3R'><tr id='xuR3R'><dt id='xuR3R'><q id='xuR3R'><span id='xuR3R'><b id='xuR3R'><form id='xuR3R'><ins id='xuR3R'></ins><ul id='xuR3R'></ul><sub id='xuR3R'></sub></form><legend id='xuR3R'></legend><bdo id='xuR3R'><pre id='xuR3R'><center id='xuR3R'></center></pre></bdo></b><th id='xuR3R'></th></span></q></dt></tr></i><div id='xuR3R'><tfoot id='xuR3R'></tfoot><dl id='xuR3R'><fieldset id='xuR3R'></fieldset></dl></div>
  • <legend id='xuR3R'><style id='xuR3R'><dir id='xuR3R'><q id='xuR3R'></q></dir></style></legend>
    <tfoot id='xuR3R'></tfoot>

  • <small id='xuR3R'></small><noframes id='xuR3R'>

    • <bdo id='xuR3R'></bdo><ul id='xuR3R'></ul>

        如何基于 URL 模式应用 Spring Boot 过滤器?

        时间:2023-09-27

            <tbody id='9RfJf'></tbody>

            <tfoot id='9RfJf'></tfoot>

            <i id='9RfJf'><tr id='9RfJf'><dt id='9RfJf'><q id='9RfJf'><span id='9RfJf'><b id='9RfJf'><form id='9RfJf'><ins id='9RfJf'></ins><ul id='9RfJf'></ul><sub id='9RfJf'></sub></form><legend id='9RfJf'></legend><bdo id='9RfJf'><pre id='9RfJf'><center id='9RfJf'></center></pre></bdo></b><th id='9RfJf'></th></span></q></dt></tr></i><div id='9RfJf'><tfoot id='9RfJf'></tfoot><dl id='9RfJf'><fieldset id='9RfJf'></fieldset></dl></div>

            <small id='9RfJf'></small><noframes id='9RfJf'>

            • <bdo id='9RfJf'></bdo><ul id='9RfJf'></ul>

                  <legend id='9RfJf'><style id='9RfJf'><dir id='9RfJf'><q id='9RfJf'></q></dir></style></legend>
                  本文介绍了如何基于 URL 模式应用 Spring Boot 过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我创建了一个 Spring Boot 过滤器 - 使用 @Component 注释实现 GenericFilterBean.

                  I have created a spring boot filter - implements GenericFilterBean with @Component annotation.

                  @Component 
                  public class MyAuthenticationFilter  extends GenericFilterBean {
                  ...
                  @Override
                  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
                  ...
                  }
                  }
                  

                  过滤器由 Spring Boot Framework 自动识别,适用于所有 REST API.我希望此过滤器仅适用于某个 URL 路径,例如 /api/secure/* 但我找不到正确的方法.我试过 @WebFilter 但没有用.我没有使用 XML 配置或 servlet 初始化程序 - 只是注释.

                  The filter is automatically identified by the Spring Boot Framework and works fine for all of the REST API. I want this filter to apply only on a certain URL path, such as /api/secure/* but I can't find the right way. I tried @WebFilter but it didn't work. I'm not using XML configuration or servlet initializer - just the annotations.

                  什么是让它工作的正确方法?

                  What would be the correct way to get it working?

                  推荐答案

                  你可以像这样添加过滤器:

                  You can add a filter like this:

                  @Bean
                  public FilterRegistrationBean someFilterRegistration() {
                  
                      FilterRegistrationBean registration = new FilterRegistrationBean();
                      registration.setFilter(someFilter());
                      registration.addUrlPatterns("/url/*");
                      registration.addInitParameter("paramName", "paramValue");
                      registration.setName("someFilter");
                      registration.setOrder(1);
                      return registration;
                  } 
                  
                  @Bean(name = "someFilter")
                  public Filter someFilter() {
                      return new SomeFilter();
                  }
                  

                  这篇关于如何基于 URL 模式应用 Spring Boot 过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:JSF 如何找到使用@ManagedBean 注释的bean? 下一篇:自定义 Jackson ObjectMapper 以读取自定义注释并屏蔽

                  相关文章

                  最新文章

                    <small id='19Pgh'></small><noframes id='19Pgh'>

                    1. <legend id='19Pgh'><style id='19Pgh'><dir id='19Pgh'><q id='19Pgh'></q></dir></style></legend>
                      <i id='19Pgh'><tr id='19Pgh'><dt id='19Pgh'><q id='19Pgh'><span id='19Pgh'><b id='19Pgh'><form id='19Pgh'><ins id='19Pgh'></ins><ul id='19Pgh'></ul><sub id='19Pgh'></sub></form><legend id='19Pgh'></legend><bdo id='19Pgh'><pre id='19Pgh'><center id='19Pgh'></center></pre></bdo></b><th id='19Pgh'></th></span></q></dt></tr></i><div id='19Pgh'><tfoot id='19Pgh'></tfoot><dl id='19Pgh'><fieldset id='19Pgh'></fieldset></dl></div>
                      • <bdo id='19Pgh'></bdo><ul id='19Pgh'></ul>
                    2. <tfoot id='19Pgh'></tfoot>