java.lang.IllegalArgumentException:过滤器映射必须指定<url-pattern>或<servlet-name>

Kon*_*sev 7 tomcat servlets resteasy servlet-filters

我用下一个web.xml创建了非常简单的REST应用程序:

<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>
Run Code Online (Sandbox Code Playgroud)

我正在使用servlet 3.0规范和Tomcat 7.0.23.不幸的是它总是失败:

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)
Run Code Online (Sandbox Code Playgroud)

我不知道问题出在哪里......我的代码中没有使用过滤器,我该如何解决?

Bal*_*usC 12

这与RESTEasy问题577有关.要解决此问题,您需要添加metadata-complete="true"到您的<web-app>根声明/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>
Run Code Online (Sandbox Code Playgroud)

这样Tomcat就会认为它/WEB-INF/web.xml是完整的,并且不会扫描JAR以获取web.xml片段中的其他元数据信息,以防RESTEasy显然包含错误/未完全声明的过滤器.