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 7429985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:04:08+00:00 2026-05-29T09:04:08+00:00

It is said that in the Spring javadoc article about DriverManagerDataSource class, that this

  • 0

It is said that in the Spring javadoc article about DriverManagerDataSource class, that this class is very simple and that it is recommended

to use a JNDI DataSource provided by the container. Such a DataSource can be exposed as a DataSource bean in a Spring ApplicationContext via JndiObjectFactoryBean

The question is: how do I accomplish this?

For example, if I wish to have DataSource bean to access my custom MySQL database, what would I require then? What should I write in the context configuration, etc?

  • 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-29T09:04:09+00:00Added an answer on May 29, 2026 at 9:04 am

    If using Spring’s XML schema based configuration, setup in the Spring context like this:

    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
    ...
    <jee:jndi-lookup id="dbDataSource"
       jndi-name="jdbc/DatabaseName"
       expected-type="javax.sql.DataSource" />
    

    Alternatively, setup using simple bean configuration like this:

    <bean id="DatabaseName" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/DatabaseName"/>
    </bean>
    

    You can declare the JNDI resource in tomcat’s server.xml using something like this:

    <GlobalNamingResources>
        <Resource name="jdbc/DatabaseName"
                  auth="Container"
                  type="javax.sql.DataSource"
                  username="dbUser"
                  password="dbPassword"
                  url="jdbc:postgresql://localhost/dbname"
                  driverClassName="org.postgresql.Driver"
                  initialSize="20"
                  maxWaitMillis="15000"
                  maxTotal="75"
                  maxIdle="20"
                  maxAge="7200000"
                  testOnBorrow="true"
                  validationQuery="select 1"
                  />
    </GlobalNamingResources>
    

    And reference the JNDI resource from Tomcat’s web context.xml like this:

      <ResourceLink name="jdbc/DatabaseName"
       global="jdbc/DatabaseName"
       type="javax.sql.DataSource"/>
    

    Reference documentation:

    • Tomcat 8 JNDI Datasource HOW-TO
    • Tomcat 8 Context Resource Links Reference
    • Spring 4 JEE JNDI Lookup XML Schema Reference
    • Spring 4 JndiObjectFactoryBean Javadoc

    Edit: This answer has been updated for Tomcat 8 and Spring 4. There have been a few property name changes for Tomcat’s default datasource resource pool setup.

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

Sidebar

Related Questions

in this answer he said that i can use RIA services while creating my
Somebody said that when your PHP code and application use global variables then it
It is currently said that MD5 is partially unsafe. Taking this into consideration, I'd
In Pro Spring 2.5 it is said that Spring doesn’t manage the life cycles
Can I just load com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource class as a bean in Spring? What are this
I was reading an article that said that Java strings are not completely immutable.
Clarification: this question is not about access modifier Confirmed that B.m() and b.m() statements
I just answered a question where I said that while string interning is good
I've heard it said that the Entity Framework is overkill or that it's difficult
It has been said that C# can be regarded as a functional programming language,

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.