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
Preface Although the holiday is over, it shows up...
This article example shares the specific code of ...
How to modify the mysql table partitioning progra...
Scenario You need to authorize the tester to use ...
background Solving browser compatibility issues i...
Preface: I used the official nginx proxy_cache as...
Table of contents From father to son From son to ...
Let me first explain why the text is not vertical...
Today, let's talk about how to use js to achi...
Most navigation bars are arranged horizontally as...
//Default protocol /The use of the default protoc...
Virtual machines are very convenient testing soft...
reason: MySQL 5.7.5 and up implements detection o...
The shell script sets access control, and the IP ...
Nginx cross-domain configuration does not take ef...