harshit
harshit

Reputation: 7951

java.lang.IllegalStateException: No filter named encodingFilter while starting spring application

I am trying to run a spring application. My web.xml looks

<?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>

and i am getting error

java.lang.IllegalStateException: No filter named encodingFilter at org.eclipse.jetty.servlet.ServletHandler.updateMappings(ServletHandler.java:1148) at org.eclipse.jetty.servlet.ServletHandler.setFilterMappings(ServletHandler.java:1249) at org.eclipse.jetty.servlet.ServletHandler.addFilterMapping(ServletHandler.java:1079)

and i am creating a jetty-pkg as jar file and run it as java -jar myjar.jar

Upvotes: 4

Views: 1698

Answers (3)

Daniel De Le&#243;n
Daniel De Le&#243;n

Reputation: 13649

Just update your web.xml XSD definition to a newer version like 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">

Upvotes: 0

harshit
harshit

Reputation: 7951

I read somewhere that <filter> should be created before <filter-mapping> . I swap the position and was able to fix it ..

Upvotes: 3

Eran Medan
Eran Medan

Reputation: 45765

What Jetty version are you using?

Could it be related to this bug?

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

Upvotes: 0

Related Questions