檢查有關資源參照注入目標合併的行為變更

在 Servlet 3.0 規格中, 中定義的資源參照的 <在 web-fragment.xml 檔案中定義的資源參照的 <injection-target> 元素 會被新增到父 web.xml 檔案中,但前提是 web.xml資源參照定義中的相同 沒有 <injection-target> 元素。 Servlet 3.1 規格闡明,對於資源的 引用的同名資源,所有 web-fragment.xml 描述符中的 <injection-target> 元素都會新增到 父 web.xml 描述符的 清單中的 <injection-target> 元素。 該 Servlet 3.1 功能可能會因啟動先前從 <span.xml 檔排除的注入目標而改變現有的應用程式行為。 web.xml 檔案中排除的目標。

此規則標記 web-fragment.xml 檔案中的 <injection-target> 元件。 檔案中的 <injection-target> 元件,如果 web.xml</span 檔案中包含 <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 行為變更