java.lang.IllegalStateException:启动spring应用程序时没有名为encodingFilter的过滤器

时间:2012-05-08 21:31:31

标签: java spring spring-mvc

我正在尝试运行一个spring应用程序。我的web.xml看起来

<?xml version="1.0" encoding="utf-8"?>
&lt;web-app   
 xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">


<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/beans.xml</param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/version/2.0/*</url-pattern>
</servlet-mapping>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/version/2.0/*</url-pattern>
</filter-mapping>
<filter>
        <filter-name>encodingFilter</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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

我收到错误

java.lang.IllegalStateException:没有名为encodingFilter的过滤器     在org.eclipse.jetty.servlet.ServletHandler.updateMappings(ServletHandler.java:1148)     在org.eclipse.jetty.servlet.ServletHandler.setFilterMappings(ServletHandler.java:1249)     在org.eclipse.jetty.servlet.ServletHandler.addFilterMapping(ServletHandler.java:1079)

我正在创建一个jetty-pkg作为jar文件并运行它 java -jar myjar.jar

3 个答案:

答案 0 :(得分:3)

我在某处读过&lt; filter&gt;应该在&lt; filter-mapping&gt;之前创建。我交换了位置并且能够解决它..

答案 1 :(得分:0)

您使用的Jetty版本是什么?

它可能与此错误有关吗?

http://jira.codehaus.org/browse/JETTY-1113

答案 2 :(得分:0)

只需将您的web.xml XSD定义更新为较新版本,例如3.1

<?xml version="1.0" encoding="utf-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">