java.lang.IllegalArgumentException: 过滤器映射必须指定一个 &lt;url-pattern&gt;或 <servlet-name> [英] java.lang.IllegalArgumentException: Filter mapping must specify either a &lt;url-pattern&gt; or a &lt;servlet-name&gt;

查看:130
本文介绍了java.lang.IllegalArgumentException: 过滤器映射必须指定一个 &lt;url-pattern&gt;或 <servlet-name>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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?

推荐答案

这与RESTEasy issue有关577.要解决此问题,您需要将 metadata-complete="true" 添加到您的 /WEB-INF/web 的 <web-app> 根声明中.xml.

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>

这样 Tomcat 将假设 /WEB-INF/web.xml 是完整的,并且不会扫描 JAR 以获取 web.xml 片段中的附加元数据信息如果 RESTEasy 显然包含错误/不完整声明的过滤器.

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.

这篇关于java.lang.IllegalArgumentException: 过滤器映射必须指定一个 &lt;url-pattern&gt;或 <servlet-name>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆