We have a web module which uses a jar file added in Web-INF/lib folder. This jar file has a utility class written by us, which is used by our application to get DB connection.
This class is a simple one which does a lookup for the datasource, fetches the connection and returns it to the caller for use.
Everything works fine, except that we are getting following 'Informational' message in Websphere SystemOut.log file :
J2CA0122I: Resource reference jdbc/DSPPP could not be located, so default values of the following are used: [Resource-ref settings]
res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
res-resolution-control: 999 (undefined)
I read in lot of articles (thanks to you guys) that a local reference should be used instead of directly looking up for the datasource name. So i followed this:
1. Created a Resouce Reference (datasource) in web.xml pointing to the JNDI Name : jdbc/DSPPP (jndi name of the datasource).
2. Used this Resource reference in the code to do lookup :
Properties p = new Properties();
//get local jndicontext
p.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory" );
p.put("com.ibm.websphere.naming.jndicache.cacheobject", "none");
javax.naming.Context jndiContext = new InitialContext(p);
DataSource ds = (DataSource) jndiContext .lookup ("java:comp/env/datasource");
Connection con = ds.getConnection();
The above code is in the Utility class i mentioned above, which is packaged in Jar and put under Web-INF/lib folder of web module.
Problem is : Seems like local reference created in web module is not visible to this utility jar. We get following error :
method.javax.naming.NameNotFoundException: Name "comp/env/datasource" not found in context "java:".
PS : If i put the above code in one of the class, directly under javasource of web module or in the
JSP, it works beautifully, without logging the annoying Informational message.
So is there anybody who can give me some pointers about :
1. What is the way to access reference created in web.xml in the utility class added as a jar in web module?
2. Is there any other way of coding to get rid of this message?
3. if nothing works, is there any setting in Websphere server, tweaking which we can supress the 'informational messages' in log files.
thanks a bunch.
Shikhar