Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7534201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:56:54+00:00 2026-05-30T05:56:54+00:00

I am trying to define a JNDI DB connection in a test project with

  • 0

I am trying to define a JNDI DB connection in a test project with Spring. I’ve bootstrapped the project with Spring Roo and thus is Mavenized. Here is the Roo script 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’ve 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’ve created src/main/resources/META-INF/context.xml with the following content:

<?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 – Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

What should I do to properly define the datasource?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:56:59+00:00Added an answer on May 30, 2026 at 5:56 am

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

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to define a function in sybase. I write this script: CREATE FUNCTION
I am trying to define a one to many relationship between Category and Project
Im trying to define a dataTemplate for a business object in my wpf application
I'm trying to define a task that emits (using echo) a message when a
I'm trying to define a table to store student grades for a online report
I am trying to define a WCF contract that returns an interface, something like
I'm trying to define a delegate function that will return an IEnumerable. I'm having
I'm trying to define a new shortcode in WordPress, and I get the following
I'm trying to define a way to simulate an case on accessing into a
I'm trying to define an action for a model Bar -- but I only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.