【问题标题】:How to order filters with Apache Tomcat 7如何使用 Apache Tomcat 7 订购过滤器
【发布时间】:2015-06-11 16:49:15
【问题描述】:

我正在使用 Spring、maven 和 Apache Tomcat 7 创建一个 Java Web 项目。在这个项目中,我有一个这样的 web.xml:

<display-name>web</display-name>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- Servlet de Spring. Definimos el Servlet que recibirá todas las peticiones que 
    se realizen a la página -->

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<!-- <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-servlet.xml</param-value>
</context-param> -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 

<absolute-ordering>
    <name>encodingFilter</name>
    <name>cors</name>
    <name>springSecurityFilterChain</name>
    <name>FileUploadFilter</name>
</absolute-ordering>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>


<filter>
    <filter-name>cors</filter-name>
    <filter-class>filters.SimpleCorsFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>cors</filter-name>
    <url-pattern>/api/*</url-pattern>
</filter-mapping>

<error-page>
    <location>/error</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/error</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error</location>
</error-page>
<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error</location>
</error-page>

当我启动 Tomcat 时,控制台上会出现以下消息:

org.apache.catalina.deploy.WebXml orderWebFragments
Used a wrong fragment name encodingFilter at web.xml absolute-ordering tag!
org.apache.catalina.deploy.WebXml orderWebFragments
Used a wrong fragment name cors at web.xml absolute-ordering tag! 
org.apache.catalina.deploy.WebXml orderWebFragments
Used a wrong fragment name springSecurityFilterChain at web.xml absolute-ordering tag!

我已经对 Apache Tomcat 6 进行了同样的尝试,但没有遇到任何问题。 有什么想法吗?

【问题讨论】:

    标签: java tomcat


    【解决方案1】:

    【讨论】:

    • 非常感谢您的回复。我检查了您发布的链接,我认为我无法实现第一个和最后一个链接的解决方案,因为我无法修改 Spring 的过滤器 web-fragments 以建立订单。我会尝试第二个选项
    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2019-07-28
    • 2015-03-28
    相关资源
    最近更新 更多