You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Jessie Xie <je...@hotmail.com> on 2015/12/30 08:44:33 UTC

The JNDI loading order



Hi Guys,
I setup a tomcat 7.0.67 web server and add two JNDIs resources into conf/server.xml which are dependent that one should been loaded first before another. 
Seems it doesn't work if I change their appearance order in server.xml. After checking the source code and I found that the loading order of JNDI resource are decided by the "HashCode" of resource name.
In 	org.apache.catalina.deploy.NamingResources.java							     /**     * The resource references for this web application, keyed by name.     */    private HashMap<String, ContextResource> resources =        new HashMap<String, ContextResource>();                           ==> new LinkedHashMap<String, ContextResource>();
And in org.apache.naming.NamingContext.java
    public NamingContext(Hashtable<String,Object> env, String name)         throws NamingException {        this.bindings = new HashMap<String,NamingEntry>();        ==> this.bindings = new LinkedHashMap<String,NamingEntry>();        ...       }
    /**     * Builds a naming context using the given environment.     */    public NamingContext(Hashtable<String,Object> env, String name,            HashMap<String,NamingEntry> bindings)         throws NamingException {        this(env, name);	this.bindings = bindings;                                   ==> if (bindings != null)	this.bindings.putAll(bindings);    }
After codes changed as above, the JNDI resources could be loaded as desired by their insertion order.
I wonder whether such modifications could be put into formal release, that It could be convenient for the user like me who have the several dependent JNDI objects.
Thank you very much,
Jessie