In my past work, the development server was generally Tomcat. The data source is often configured by configuring a dataSource bean in applicationContext.xml Then modify the JNDI configuration during deployment I guess it's because Tomcat's configuration needs to be changed Unlike JBoss, WebLogic and other servers, you can directly add JNDI data sources in the management interface Few people study its configuration. I recently did a small project. When releasing the version, I compiled it into a jar package through ant and then threw it to the test The tester is the boss. He was taught to modify the data source, but he pretended not to hear it. I was bored on the weekend and read some Tomcat configuration tutorials. Here are some summaries Note: If your project is directly dropped under webapps, there will be no Context node corresponding to the project in server.xml Update: Since some of the previous configurations came from the Internet and were not very useful, some updates were made Some personal comments on each method PS: The following configuration has been tested under apache-tomcat-6.0.35 and can access the database The first type is a single application with exclusive data sourceIn the first step, find Tomcat's server.xml, find the project's Context node, and add a private data source <Context docBase="WebApp" path="/WebApp" reloadable="true" source="org.eclipse.jst.jee.server:WebApp"> <Resource name="jdbc/mysql" scope="Shareable" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" url="jdbc:mysql://localhost:3306/test" driverClassName = "com.mysql.jdbc.Driver" username="root" password="root" /> </Context> Advantages: Simple Disadvantages: poor reusability The second method is to configure a global JNDI data source and apply it to a single application.Two Steps The first step is to find the GlobalNamingResources node in Tomcat's server.xml and add a global data source under the node <Resource name="jdbc/mysql" scope="Shareable" type="javax.sql.DataSource" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" url="jdbc:mysql://localhost:3306/test" driverClassName = "com.mysql.jdbc.Driver" username="root" password="root" /> <script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> The second step is to find the project Context node to which this JNDI data source is to be applied, and add a reference ResourceLink to the global data source. <Context docBase="WebApp" path="/WebApp" reloadable="true"> <ResourceLink global="jdbc/mysql" name="jdbc/mysql" type="javax.sql.DataSource" /> </Context> Advantages: reusability, controllability Disadvantages: The configuration is more complicated than the third method, and each project must be configured The third method is to configure a global JNDI data source and apply it to all applications deployed under Tomcat.Also divided into two steps first step Refer to the first step of the second method The second step is to find Tomcat's context.xml and add a ResourceLink node under the Context node to reference the data source configured in the first step. The root node of this XML configuration file is <Context> <Context> <ResourceLink global="jdbc/mysql" name="jdbc/mysql" type="javax.sql.DataSource" /> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Context> Advantages: reusability, one-time implementation Disadvantages: no controllability Spring reference to JNDI data sourceAdd a bean in applicationContext.xml to replace the original dataSource <jee:jndi-lookup id="dataSource" jndi-name="jdbc/mysql" /> Configuration of C3P0 data sourceThe values of type and factory have changed username=>user url=>jdbcUrl driverClassName=>driverClass <Resource name="jdbc/mysql_c3p0" scope="Shareable" type="com.mchange.v2.c3p0.ComboPooledDataSource" factory="org.apache.naming.factory.BeanFactory" jdbcUrl="jdbc:mysql://localhost:3306/test" driverClass="com.mysql.jdbc.Driver" user="root" password="root" /> This concludes this article about the three ways to configure JNDI data source for Tomcat. For more information about configuring JNDI data source for Tomcat, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of clipboard.js usage
>>: Web Theory: Don't make me think Reading Notes
As the first article of this study note, we will ...
Table of contents Immediately execute function fo...
Preface As we all know, JavaScript is single-thre...
In order to make the page display consistent betwe...
In the table header, you can define the dark bord...
From handicraft design to graphic design to web de...
We deal with Linux servers every day, especially ...
1. Simulate database data 1-1 Create database and...
The company had a well-configured server that was...
Copy code The code is as follows: <HTML> &l...
<br />For some time, I found that many peopl...
Scenario Yesterday the system automatically backe...
During today's lecture, I talked about the di...
1. Description In MySQL, when we need to get the ...
Table of contents Project Directory Dockerfile Fi...