请有人帮助我,当我在 web.xml 中放置 async-supported 标签时出现此错误:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-role-ref}' is expected.
这是我的 web.xml
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.yeditepeim.messenger.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
最佳答案
web.xml 是一个 XML 模式。如果您不熟悉 XML 模式,它们会描述 XML 文档可以包含哪些元素和属性,以便成为该模式的有效实例。
话虽如此,您可以在架构位置看到正在使用的架构文件的版本,即 ...web-app_2_5.xsd
。这意味着您的 web.xml 将基于该版本的架构,该版本映射到该版本的 servlet 规范,在您的情况下是 2.5
。这样做的问题是异步直到 3.0 才被引入到 servlet 规范中。所以在 2.5 模式中没有元素规范。因此,在验证 xml 时,它表示文档中不允许使用此类元素 <async-supported>
,因为它不符合架构。
要修复它,只需将版本更改为 3.0 并将架构文件更改为 3_0
<!-- change to 3.0 -->
<web-app version="3.0"
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">
<!-- change to 3_0 -->
关于jersey - <async-supported>true</async-supported> 在 web.xml 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36740624/