[logback-user] jndi db access in tomcat5.5

Diego Louzán dlouzan at apache.org
Tue Jul 15 09:09:06 CEST 2008


Thanks for the quick answer, see inline response.

Anton Tagunov escribió:
> Hello Diego,
> 
> [1]
> 
>> using tomcat5.5, username/password can't be specified when 
>> trying to use a JNDI-shared DataSource
>> when using pooled data sources the user and 
>> password version of getConnection method can't be used.
>> I don't know if this is tomcat-specific behaviour.
> 
> this is indeed an iteresting question;
> do we have anybody here with a better knowledge of J2EE?
> 
>> ... in ... ch.qos.logback.core.db.JNDIConnectionSource:
>> Maybe some sort of "if jndi then don't use user/pass" testing could be done 
>> for better error reporting
> 
> I guess if the answer to prev. question is positive this could be a worthy idea
> 
> [2]
> 
>> Added to that, the JNDI name used in the "jndiLocation" must be 
>> prepended by "java:comp/env", as this is the standard context for java 
>> objects and the JNDIConnectionSource does not prepend the searched values with it.
> 
> Looks like a nice idea to me.
> Will not be backwards compatible but logback is not version 1 yet.
> I suggest that you create a Jira item for this /and maybe attach a patch/

In my company we have our own DataSourceLocator class that abstracts the 
JNDI lookup and automagically prepends all searched keys with 
"java:comp/env" but this is obviously custom behaviour.

There are two options here: document the need for the prefix in the 
manual or add the prefix to all keys in the JNDIConnectionSource class. 
I'd suggest the former option as the best one, but as you already 
pointed out, backwards compatibility is lost in the way.

> 
> [3]
> 
>> Another thing I got problems with was slf4j's jcl-over-slf4j-1.5.2.jar. 
>> logback ... initialized too early when using jcl-over-slf4j, before tomcat 
>> makes the JNDI resources available to the web application
> 
>> ch.qos.logback.core.db.JNDIConnectionSource at 67c1a6 - Error while getting 
>> data source javax.naming.NameNotFoundException:
>> javax.naming.NameNotFoundException: 'comp' can't be found in this context
>>         at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> ...
>> org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
>> org.apache.commons.logging.LogFactory.getLog(LogFactory.java:704)
>> org.apache.catalina.core.ContainerBase.getLogger(ContainerBase.java:381)
> ...
>> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
> 
> Looks pretty weird to me. Diego what folder is jcl-over-slf4j-1.5.2.jar in?
> Do you have another copy in shared tomcat libraries? Or together with tomcat own jars?

I tested including jcl-over-slf4j in both the webapp WEB-INF/lib dir and 
in global tomcat common/lib. Got the same error both times.

The pattern is as follows: have a perfectly working app with logging 
working with slf4j + logback; then include jcl-over-slf4j jar and get 
the JNDI NameNotFoundException. Maybe I'm wrong, but I'm pretty sure 
this is related to tomcat using JCL internally for logging in the 
catalina engine, way before the webapp is ready.

One question is if this problem would happen if the datasource was 
defined as global to all tomcat webapps (defined in the global context), 
instead of being a webapp-defined datasource. My guess is that it will 
work because that JNDI object will probably be defined and running 
before the webapps are initialized (but this is only a guess on the 
internal behaviour of tomcat!).

> 
> Cheers, Anton Tagunov
> logback user
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user

Regards.
Diego.



More information about the Logback-user mailing list