Topic
  • 2 replies
  • Latest Post - ‏2010-12-07T16:21:06Z by pandeybrijesh
SystemAdmin
SystemAdmin
4447 Posts

Pinned topic resource-ref in web.xml not being loaded into InitialContext

‏2005-07-13T20:36:50Z |
I am working in WSAD 5.1.1 and DB2 8
I have an EAR with one WAR and two EJB JARS.
I am testing in the WASD Test Environment.
I have a connection factory class that gets a reference to my datasource from the initial context. Initially a direct JNDI lookup was being preformed. This allowed the application to work but resulted in everybodys favorite informational message that the resourse referece could not be found and the defaults are being used. I have been trying to get rid of that message by performing an indrect lookup. Here is what I did:

1. Opened up the WAR deployment descriptor in WSAD
2. Selected the Resource tab on the References page
3. Pressed 'Add' and entered the following:
3.1 Name => test
3.2 Type => javax.sql.DataSource
3.3 Authentication => Container
3.4 Connection Management => Default
3.5 Isolation Level => TRANSACTION_NONE
3.6 JNDI Name => jdbc/MktgCycleXAPool

This resulted in the following updated to web.xml

[b]web.xml from WAR[/b]
...
<resource-ref id="ResourceRef_1121263625578">
<res-ref-name>test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>CONTAINER</res-auth>
</resource-ref>
...

I updated the connection factory class to get the java:comp/env subcontext and then perform a lookup of the new reference name 'test'

code
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");

ctx = new InitialContext(env);
ctx2 = (Context)ctx.lookup("java:comp/env");
ds = (DataSource) ctx2.lookup("test");
[/code]
This connection pool is also flagged as a CMP pool.

Below is the message from the console log at start up. From what I can tell, it looks like the resource reference is not making it into the context. Did I miss something?

[b]Server start up log[/b]

EJBContainerI E WSVR0062E: Unable to start EJB, Marketing#ejb_mkt.jar#SuppressionBO: javax.naming.NameNotFoundException: Name "test" not found in context "java:comp/env".
Thanks in advance.
Updated on 2010-12-07T16:21:06Z at 2010-12-07T16:21:06Z by pandeybrijesh
  • SystemAdmin
    SystemAdmin
    4447 Posts

    Re: resource-ref in web.xml not being loaded into InitialContext

    ‏2005-07-13T21:22:45Z  
    I have found out what the problem is. The connection factory class lives inside one of the EJB Jars. It does not have easy access to the resource references in the WAR. What I needed to do was set up a resource reference for each ejb. This is very similar to setting up ejb local references when one ejb references another.
  • pandeybrijesh
    pandeybrijesh
    1 Post

    Re: resource-ref in web.xml not being loaded into InitialContext

    ‏2010-12-07T16:21:06Z  
    I have found out what the problem is. The connection factory class lives inside one of the EJB Jars. It does not have easy access to the resource references in the WAR. What I needed to do was set up a resource reference for each ejb. This is very similar to setting up ejb local references when one ejb references another.
    Hi ,
    in case of ejb, we should to make connection in server side in application deployment decriptor file.
    so we can easly get lookup JNDI and get the parameter.
    we can also use service locator class.