tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian <cm...@famiru.de>
Subject JNDI initialization since Tomcat 8.0.1
Date Sun, 13 Apr 2014 11:10:17 GMT
Hi,

I'm experimenting with java 8, spring data JPA, hibernate and tomcat 8.
Spring Data JPA initializes hibernate on deployment.

On tomcat 8.0.0-RC10 everything is fine. Using Tomcat 8.0.1 or newer, an
exception is thrown when hibernate tries to fetch the datasource from JNDI:

javax.naming.NameNotFoundException: Name [java:comp/env/jdbc/myDB] is
not bound in this Context. Unable to find [java:comp].
	at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
	at javax.naming.InitialContext.lookup(InitialContext.java:421)
	at
org.hibernate.engine.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:114)
	...

The part of the thread dump concerning tomcat:
...
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4737)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5159)
	- locked <0x1aea> (a org.apache.catalina.core.StandardContext)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1646)
...


When I disable hibernate and use the following snippet in a controller,
the DataSource is returned correctly:
Context initCtx = new InitialContext();
DataSource dataSource = (DataSource)
initCtx.lookup("java:comp/env/jdbc/myDB");

I have configured the datasource in META-INF/context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/">
    <Resource name="jdbc/myDB"
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost:3306/test"/>
</Context>

And referenced it in web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <resource-ref>
        <res-ref-name>jdbc/myDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

Of course the mysql driver is copied into $CATALINA_BASE/lib.

Has the JNDI initialization changed between tomcat 8.0.0-RC10 and 8.0.1?

Regards,

Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message