2014-04-13 15:10 GMT+04:00 Christian <cm...@famiru.de>: > 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: > > (....) > ... > 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? >
Is hibernate initialized via a <listener> in web.xml, or where? "path" attribute cannot be used in META-INF/context.xml file. The driver jar should be in one place, not both. IIRC, a) classloading for drivers was changed at some point, to allow them in WEB-INF/lib b) different versions of Tomcat 8 use different versions of Apache Commons DBCP 2 pool The visible part of JNDI depends on Thread.currentThread().getContextClassLoader() (aka TCCL). Any reason why TCCL may be wrong? (You aren't providing the full stacktrace) Maybe you can try debugging, with a breakpoint in org.apache.naming.* classes? http://wiki.apache.org/tomcat/FAQ/Developing#Debugging Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org