In the Servlet 3.0 specification, the <injection-target> elements of a resource reference that is defined in a web-fragment.xml file are added to the parent web.xml file only if the web.xml resource reference definition with the same name has no <injection-target> elements. The Servlet 3.1 specification clarifies that for a resource reference of the same name, all <injection-target> elements in web-fragment.xml descriptors are added to the parent web.xml descriptors list of <injection-target> elements. The Servlet 3.1 feature might change existing application behavior by activating injection targets that were previously excluded from the web.xml file.
This rule flags the <injection-target> element in the web-fragment.xml file if the web.xml file contains an <injection-target> element within a <resource-ref> element that is defined with the same name as the <resource-ref> element in the web-fragment.xml file.
The following examples demonstrate the behavior change when you use a combination of a web.xml file and a web-fragment.xml file:
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>
In Servlet 3.0 the combined result ignores the injection target for 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>
In Servlet 3.1 the combined result uses the injection target for 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>
For more information on Servlet 3.1 behavior changes, see the following resource: Servlet 3.1 behavior changes.