java.lang.IllegalArgumentException: Filter mapping must specify either a <url-pattern> or a <servlet-name>

狂风中的少年 提交于 2020-02-03 04:37:05

问题


I've created very simple REST app with next web.xml:

<context-param>
    <param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>

<listener>
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>

<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

I'm using servlet 3.0 specification and Tomcat 7.0.23. Unfortunately it fails all time:

Caused by: java.lang.IllegalArgumentException: Filter mapping must specify either a <url-pattern> or a <servlet-name>
    at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:2995)
    at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2954)

I don't imagine where problem is... I don't use filters in my code, how can I fix it?


回答1:


This is related to RESTEasy issue 577. To fix this, you need to add metadata-complete="true" to the <web-app> root declaration of your /WEB-INF/web.xml.

<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0" metadata-complete="true">

    <!-- Config here. -->

</web-app>

This way Tomcat will assume that the /WEB-INF/web.xml is complete and won't scan JARs for additional metadata information in web.xml fragments which in case of RESTEasy apparently contain incorrectly/incompletely declared filters.




回答2:


Of course, adding 'metadata-complete="true"' will block any other jars from contributing to web.xml, including RichFaces and Seam. It is better to exclude the offending JAR file from your deployment. In my case, it was the async-http-servlet-3.0-2.3.3.Final.jar who offended.




回答3:


It's a bug in Tomcat 7 (version < 7.0.28), see that reply to a similar question, and the linked Tomcat 7 bugzilla ticket.



来源:https://stackoverflow.com/questions/8581770/java-lang-illegalargumentexception-filter-mapping-must-specify-either-a-url-pa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!