Spring configuration JNDI Solution

Source: Internet
Author: User

Spring configuration JNDI Solution

My configuration environment is: Spring + Tomcat + MySQL

Note:

1. $ TOMCAT_HOME indicates the Tomcat installation directory.

Step 1: configure the data source in the $ TOMCAT_HOME/conf/context. xml file of Tomcat.

<Resource
Name = "jdbc/TestDB"
Auth = "Container"
Type = "javax. SQL. DataSource"
MaxActive = "100"
MaxIdle = "30"
MaxWait = "10000"
DriverClassName = "com. mysql. jdbc. Driver"
Url = "jdbc: mysql: // localhost: 3306/TestDB"
Username = "root"
Password = "123456"
/>

Parameter description:

Name: the name of the JNDI, which will be referenced when Spring loads the JNDI.

DriverClassName: full name of the database Driver Class.

Url: the url of the database connection.

Username: database user name.

Password: password of the database user.

Other parameters are connection optimization parameters, which can be queried by Google.

Step 2: copy the Mysql driver package to the $ TOMCAT_HOME/lib directory.

Step 3: Let Spring load the JNDI configuration and add the following configuration to the Spring configuration file:

<Bean id = "dataSource" class = "org. springframework. jndi. JndiObjectFactoryBean">
<Property name = "jndiName" value = "jdbc/TestDB"/>
<Property name = "resourceRef" value = "true"/>
</Bean>

Parameter description:

JndiName: the separate JNDI name configured in step 1.

ResourceRef: We can omit the prefix "java: comp/env/" when specifying jndiName /".

Note:

It is okay to start the Tomcat container test application. Since JNDI is configured in the Tomcat container, the Junit test will always fail. If any of you have a solution, please let me know. Thank you!

How to configure Hibernate transactions in Spring

Struts2 Spring integration methods and principles

Design and implement RESTful Web Services Based on Spring

Spring-3.2.4 + Quartz-2.2.0 integrated instance

Use Spring for unit testing

Use Spring annotations to implement Netty server-side UDP applications

Spring 3.x enterprise application development practice PDF complete HD scan version + source code

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.