Tomcat vs Weblogic JNDI Lookup

前端 未结 8 1966
死守一世寂寞
死守一世寂寞 2020-11-28 07:23

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 whe

8条回答
  •  一个人的身影
    2020-11-28 07:31

    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 and spring-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:

    • A entry in web.xml for your app to use a single name
    • A file WEB-INF/weblogic.xml to map your jndi name to the resource managed by WebLogic
    • A file META-INF/context.xml to map your jndi name to the resource managed by Tomcat
      • This can be either in the Tomcat installation or in your app.

    As a general rule, prefer to have your jndi names in your app like jdbc/MyDataSource and jms/ConnFactory and avoid prefixing them with java: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

    
        My data source
        jdbc/appds
        javax.sql.DataSource
        Container
    
    

    weblogic.xml

    
    
    
    
        appds
        jdbc/appds
    
    
    

    META-INF/context.xml (for Tomcat)

    
        
    
    

提交回复
热议问题