检查资源引用注入目标合并过程的行为更改

在 Servlet 3.0 规范中, 中定义的资源引用的 资源引用的 <injection-target> 元素,该资源引用在 web-fragment.xml 文件中定义的资源引用的 <injection-target> 元素 元素被添加到父 web.xml 文件中,前提是 web.xml 资源引用定义中的同名 中没有 <injection-target> 元素。 Servlet 3.1 规范明确指出,对于同名的资源引用 同名的资源引用,<span.xml 描述符中的所有 web-fragment.xml 描述符中的 <injection-target> 元素都会添加到 父 web.xml 描述符中的所有 <injection-target> 元素。 的 <injection-target> 元素列表中。 该 Servlet 3.1 功能可能会激活注入目标,从而改变现有的应用程序行为。 目标,从而改变现有的应用程序行为。这些目标以前被排除在 web.xml 文件之外。

如果web-fragment.xml 文件中的<injection-target>元素在<span.xml class="FilePath">web 文件中的 <injection-target> 元素。 文件中包含一个 <injection-target> 元素,而该 <injection-target> 元素是在 <resource-ref> 元素中定义的。 与 与 web-fragment.xml 文件中的 <resource-ref> 元素名称相同。

以下示例说明了使用 web.xml 文件和 web-fragment.xml 文件组合时的行为更改:

web.xml:

<resource-ref>
	<res-ref-name>ReferenceName</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
	<injection-target>
		<injection-target-class>Class1</injection-target-class>
		<injection-target-name>Resource1</injection-target-name>
	</injection-target>
</resource-ref>

web-fragment.xml:

<resource-ref>
	<res-ref-name>ReferenceName</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
	<injection-target>
		<injection-target-class>Class2</injection-target-class>
		<injection-target-name>Resource2</injection-target-name>
	</injection-target>
</resource-ref>

在 Servlet 3.0 中,组合的结果将忽略 Class2 的注入目标:

<resource-ref>
	<res-ref-name>ReferenceName</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
	<injection-target>
		<injection-target-class>Class1</injection-target-class>
		<injection-target-name>Resource1</injection-target-name>
	</injection-target>
</resource-ref>

在 Servlet 3.1 中,组合的结果将使用 Class2 的注入目标:

<resource-ref>
	<res-ref-name>ReferenceName</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
	<injection-target>
		<injection-target-class>Class1</injection-target-class>
		<injection-target-name>Resource1</injection-target-name>
	</injection-target>
	<injection-target>
		<injection-target-class>Class2</injection-target-class>
		<injection-target-name>Resource2</injection-target-name>
	</injection-target>
</resource-ref>

有关 Servlet 3.1 行为更改的更多信息,请参阅以下资源:Servlet 3.1 behavior changes