Search code examples
weblogicdatasourcejndijboss-eap-6

DataSource naming JBossEAP 6.2 vs Web Logic


I am porting a suite of related applications from WebLogic to JBoss EAP v6.2.

I have set up a data source connection using the JBoss command line interface and hooked it to an oracle database. This database has a name of "mydatasource" and a JNDI name of "java:jboss/datasources/mydatasource" as per JBoss standards. I can test and validate this database connection.

However, when I try to port the code and run it, the connection doesn't work. The code that worked in WebLogic was simply:

    InitialContext ic = new InitialContext() ;
    DataSource ds = (DataSource)ic.lookup(dataSource) ;

with a value in dataSource of "mydatasource".

This worked in Web Logic but in JBoss it throws a NameNotFoundException

javax.naming.NameNotFoundException: mydatasource-- service jboss.naming.context.java.mydatasource

Clearly there is a difference in how the InitialContext is set up between the two servers.

But this port involves a large number of small applications, all of which connect to the datasource via code like that above. I don't want to rewrite all that code.

Is there a way through configuration (InitialContextFactory, maybe) to define the initial context such that code like that above will work without rewriting, or perhaps is there another way of naming the datasource that JBoss will accept that would allow code like that above to work without rewriting?

Or must we bite the bullet and accept that this code needs a rewrite?

Update: Yes, I know that simply passing "java:jboss/datasources/mydatasource" to the InitialContext lookup solves the problem, but I am looking for a solution via configuration, rather than via coding if there is such a solution.


Solution

  • The way to do this correctly through configuration is to use

    java:comp/env/jdbc/myDataSource

    then use resource-ref in web.xml to map it to the declare datasource and use weblogic.xml or jboss-web.xml to actually map it to the real one

    in weblogic admin console, when you define datasource it can be jdbc/realDataSource

    JNDI path Tomcat vs. Jboss

    For weblogic http://docs.oracle.com/cd/E13222_01/wls/docs103/jdbc_admin/packagedjdbc.html