我使用下一个 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>
我正在使用 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)
我想不出问题出在哪里...我没有在我的代码中使用过滤器,我该如何解决?
最佳答案
这与 RESTEasy issue 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>
这样 Tomcat 将假定 /WEB-INF/web.xml
是完整的,不会扫描 JAR 以获取 web.xml
中的其他元数据信息在 RESTEasy 的情况下,片段显然包含错误/不完整声明的过滤器。
关于tomcat - java.lang.IllegalArgumentException : Filter mapping must specify either a <url-pattern> or a <servlet-name> 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8581770/