The Weblogic servers we are using have been configured to allow JNDI datasource names like "appds".
For development (localhost), we might be running Tomcat and when declared in the <context> section of server.xml, Tomcat will hang JNDI datasources on "java:comp/env/jdbc/*" in the JNDI tree.
Problem: in Weblogic, the JNDI lookup is "appds" whilst in Tomcat, it seems that that I must provide the formal "java:comp/env/jdbc/appds". I'm afraid the Tomcat version is an implicit standard but unfortunately, I can't change Weblogic's config … so that means we end up with two different spring config files (we're using spring 2.5) to facilitate the different environments.
Is there an elegant way to address this. Can I look JNDI names up directly in Tomcat? Can Spring take a name and look in both places? Google searches or suggestions would be great.
Best Answer
How to use a single JNDI name in your web app
I've struggled with this for a few months myself. The best solution is to make your application portable so you have the same JNDI name in both Tomcat and Weblogic.
In order to do that, you change your
web.xml
andspring-beans.xml
to point to a single jndi name, and provide a mapping to each vendor specific jndi name.I've placed each file below.
You need:
<resource-ref />
entry in web.xml for your app to use a single nameWEB-INF/weblogic.xml
to map your jndi name to the resource managed by WebLogicMETA-INF/context.xml
to map your jndi name to the resource managed by TomcatAs a general rule, prefer to have your jndi names in your app like
jdbc/MyDataSource
andjms/ConnFactory
and avoid prefixing them withjava:comp/env/
.Also, data sources and connection factories are best managed by the container and used with JNDI. It's a common mistake to instantiate database connection pools in your application.
spring
web.xml
weblogic.xml
META-INF/context.xml (for Tomcat)