Refer to my two articles: Configuring MySQL DBCP
And an individual file at/META-INF/context. xml
1. Context Configuration
Configure the jdni data source to your context, which is selected in/META-INF/context. configuration in the XM file (if the application is packaged and published using war, Tomcat will perform two steps when the application runs for the first time: 1. copy/META-INF/context.xml
To$CATALINA_BASE/conf/[enginename]/[hostname]/
2. Change the file name to the application context name ).
For example:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <context Path = "/messageboard" reloadable = "true"> <br/> <! -- Configure the data source --> <br/> <resource auth = "Container" driverclassname = "com. mySQL. JDBC. driver "maxactive =" 100 "maxidle =" 30 "maxwait =" 10000 "name =" JDBC/messageboard "Password =" XXX "type =" javax. SQL. datasource "url =" JDBC: mysql: /localhost: 3306/messageboard? Autoreconnect = true "username =" XXX "/> <br/> </context>
Note: docbase properties are not required in/META-INF/context. xml
(See the context container section in Apache Tomcat configuration reference ).
2. Web. xml configuration
Configure the <resource-ref> element for/WEB-INF/Web. xml.
For example:
<Resource-ref> <br/> <description> MySQL DBCP </description> <br/> <res-ref-Name> JDBC/messageboard </RES-ref-Name> <br/> <res-type> javax. SQL. datasource </RES-type> <br/> <res-auth> container </RES-auth> <br/> </resource-ref>
After the preceding configuration, you can use the JNDI datasource.