Reputation: 624
I'm new at Java Spring and Hibernate and I'm trying to build an application with those technologies (Maven, Spring and Hibernate). When I try to run it I receive an error from the glassfish server, It's a very long stacktrace, but this is the last part:
Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.apache.catalina.LifecycleException:
javax.naming.NameNotFoundException: CentricJavaDB not found
I'm trying things out for hours but I don't find my mistake. I'm pretty sure it's in a configuration xml file but I can't fix it. I hope some of u guys can help me (:
The configuration files:
Dispatcher servlet in the WEB-INF folder:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="controllers"/>
<context:component-scan base-package="service"/>
<bean name = "klantDao" class="service.JpaKlantDao"/>
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/CentricJavaDB"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>domain</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
</property>
</bean>
<bean id="transactionManager"
class=" org.springframework.orm.jpa.JpaTransactionManager ">
<constructor-arg ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
glassfish-web.xml in WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<Resource name="jdbc/CentricJavaDB" auth="Container"
driverClassName="com.mysql.jdbc.Driver"
username="root"
password="root"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/centricjavadb" />
</glassfish-web-app>
I also found this file "Other Sources\Setup\glassfish-resources.xml". I don't see big differences with "glassfish-web.xml" but it also contains database information. I think it also could be important:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
fail-all-connections="false"
idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="jdbc/CentricJavaDB"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.DataSource"
statement-timeout-in-seconds="-1"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"
jndi-name="jdbc/CentricJavaDB"
wrap-jdbc-objects="false">
<property name="serverName" value="localhost"/>
<property name="portNumber" value="3306"/>
<property name="databaseName" value="centricjavadb"/>
<property name="User" value="root"/>
<property name="Password" value="root"/>
<property name="URL" value="jdbc:mysql://localhost:3306/centricjavadb"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
</resources>
I think the error is caused because of the jndi-lookup can't find the datasource in glassfish-web.xml, but correct me if I'm wrong.
I think this should be enough information. If you want more files, stacktraces or whatever, just ask and I will post it.
Upvotes: 1
Views: 689
Reputation: 8067
JNDI resources are often tricky to figure out.
Stacktrace points to a problem with how you data source is defined. According to documentation :
Expect to find the JNDI name of a JDBC resource in java:comp/env/jdbc
Trying putting the following in your config:
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/CentricJavaDB"/>
Though according to this question: Spring 3 JNDI look up in glassfish3 this is not necessary
Upvotes: 1