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: