Search code examples
servletsjakarta-eejndiweb.xmlweb-fragment

Multiple web fragments with the same res-ref-name


  1. What would happen if I have multiple web-fragments which declare resource-refs with the same res-ref-name in case of:

    • The resource-refs have the same res-type
    • The resource-refs have different res-type
  2. Also what would happen if there is a resource-ref with the same res-ref-name in the web.xml in case of:

    • The resource-refs have the same res-type
    • The resource-refs have different res-type

I'm looking for what the specs are saying and not "try it to find out".


Solution

  • The Java Servlet Specification Version 3.1 has the following to say in §8.2.1:

    The requirements about name uniqueness that exist currently for a single web.xml also apply to the union of a web.xml and all applicable web-fragment.xml files.

    and §14.4 says:

    The res-ref-name specifies the name of a resource manager connection factory reference. The name is a JNDI name relative to the java:comp/env context. The name must be unique within a deployment file.

    Therefore your application should fail to deploy.