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

在 Servlet 3.0 規格中,僅當具有相同名稱的 web.xml 資源參照定義沒有 <injection-target> 元素時,才會將 web-fragment.xml 檔中所定義資源參照的 <injection-target> 元素新增至母項 web.xml 檔。對於相同名稱的資源參照,Servlet 3.1 規格澄清 web-fragment.xml 描述子中的所有 <injection-target> 元素,皆會新增至 <injection-target> 元素的母項 web.xml 描述子清單。此 Servlet 3.1 特性可能會透過啟動先前從 web.xml 檔中排除的注入目標,來變更現有應用程式行為。

如果 web.xml 檔在 <resource-ref> 元素(使用與 web-fragment.xml 檔中 <resource-ref> 元素相同的名稱進行定義)內包含 <injection-target> 元素,此規則會標示 web-fragment.xml 檔中的 <injection-target> 元素。

下列範例將示範組合使用 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 行為變更