NameNotFoundException: jdbc name is not related in this context

I am trying to define a JNDI DB connection in a test project with Spring. I downloaded the project using Spring Roo and thus Mavenized. Here is the Roo script link for reference (Roo 1.2.1)

project --topLevelPackage org.obliquid.cpool jpa setup --database MYSQL --provider HIBERNATE --jndiDataSource /jdbc/cpool web mvc setup entity jpa --class org.obliquid.cpool.entity.Person field string --fieldName name web mvc scaffold --class ~.entity.Person web mvc all --package ~.web 

In src/main/resources/META-INF/spring/applicationContext.xml I have the following (created by Roo):

 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> ... <jee:jndi-lookup id="dataSource" jndi-name="/jdbc/cpool" resource-ref="true"/> ... 

I created src/main/resources/META-INF/context.xml with the following contents:

 <?xml version="1.0" encoding="UTF-8"?> <Context path="/myapp" docBase="cpool" reloadable="true" debug="1"> <Resource name = "jdbc/cpool" auth = "Container" type = "javax.sql.DataSource" username = "dbusername" password = "dbpassword" driverClassName = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:3306/dbname?DateTimeBehavior=convertToNull&amp;characterEncoding=UTF-8" maxActive = "100" maxIdle = "4" maxWait = "20000" removeAbandoned = "true" removeAbandonedTimeout="600" logAbandoned="true"/> </Context> 

However, when I try to run the application in Tomcat 7.0, I get the following error:

ERROR org.springframework.web.context.ContextLoader - Error initializing the context org.springframework.beans.factory.BeanCreationException: Error creating bean named 'dataSource': init method call failed; inested exception is javax.naming.NameNotFoundException: jdbc name is not related in this context

What should I do to correctly determine the data source?

+7
source share
1 answer

The context.xml file must be in the META-INF directory of the war file. It should not be in the class directory or in the jar file.

Place the META-INF directory with context.xml in the directory containing the webapp root in the source folder tree.

+11
source

All Articles