我正在为一个JEE5 Web服务编写单元测试。Web服务的行为取决于
为了确定是否可能,我尝试了一下是否可以拆分出
然而,我在
(如果有其他方法将一个 web.xml 文件分成较小的部分也可以接受。) 更新 如果我删除 DTD 引用,像这样:...
web.xml
文件中设置的属性。因此,我想将我的web.xml
文件分成一个常量部分和在测试运行之间进行更改的部分。为了确定是否可能,我尝试了一下是否可以拆分出
welcome-file-list
属性。使用我找到的一些说明,我得到了以下结果:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" [
<!ENTITY fragment SYSTEM "fragment.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">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>NewWebService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>NewWebService</servlet-name>
<url-pattern>/NewWebService</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
&fragment;
</web-app>
fragment.xml
<?xml version="1.0" encoding="UTF-8"?>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
然而,我在
web.xml
文件上遇到了验证错误:
我感觉问题出在使用一个 v2.3 的 web app DTD 和一个 v2.5 的 schema 在同一个文件中,但我不知道如何解决。元素类型“web-app”必须声明属性“version”。[7]
元素类型“web-app”必须声明属性“xmlns”。[7]
元素类型“web-app”必须声明属性“xmlns:xsi”。[7]
元素类型“web-app”必须声明属性“xsi:schemaLocation”。[7]
(如果有其他方法将一个 web.xml 文件分成较小的部分也可以接受。) 更新 如果我删除 DTD 引用,像这样:...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app[
<!ENTITY fragment SYSTEM "fragment.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">
etc, etc, etc.
看起来验证过程忽略了web-app_2_5.xsd
文件:
元素类型"web-app"必须声明。[5]
元素类型"listener"必须声明。[6]
元素类型"listener-class"必须声明。[7]
元素类型"servlet"必须声明。[9]
等等,等等。