Tomcat6 adds the MySQL JNDI Data Source

Source: Internet
Author: User

1. Add the JNDI configuration file to the Project

<? 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: aop = "http://www.springframework.org/schema/aop"
Xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: jdbc = "http://www.springframework.org/schema/jdbc"
Xmlns: context = "http://www.springframework.org/schema/context"
Xmlns: util = "http://www.springframework.org/schema/util">

<Bean id = "dataSource" class = "org. springframework. jndi. JndiObjectFactoryBean">
<Property name = "jndiName" value = "java: comp/env/jdbc/myDataSource"/>
<SPAN style = "WHITE-SPACE: pre"> </SPAN> <property name = "expectedType" value = "javax. SQL. DataSource"/>
</Bean>

</Beans>

2. Add the database connection configuration in Tomcat. The specific location is/conf/context. xml under the Tomcat installation directory.

Note that the name must correspond to the second half of java: comp/env in jndiName in the above Spring configuration file.

<Resource name = "jdbc/myDataSource"
Auth = "Container" type = "javax. SQL. DataSource"
Password = "test" username = "test"
DriverClassName = "com. mysql. jdbc. Driver"
Url = "jdbc: mysql: // 192.168.229.97: 3306/test"
MaxActive = "100" maxIdle = "30" maxWait = "5000"/>

3. Add the JDBC driver mysql-connector-java-5.1.6.jar of MySQL to the lib directory of Tomcat, otherwise Tomcat will report an exception that cannot find the driver class.

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.