Tomcat8.0 Configuring JNDI Data Source Complete Example

Source: Internet
Author: User
Tags auth

Jndi configuration: This configuration requires that the data source be configured in the Server.xml and context.xml of Tomcat and referenced in the project.

We need to add the jar package of the database connection under Tomcat, the download address of the related package is shown below (ojdbc14;c3p0 data source):

http://download.csdn.net/detail/qq_35624642/9778118

The first step was to find the Globalnamingresources node in Tomcat's Server.xml and add a global data source under the node, where I added two data sources.


<!--Global JNDI Resources
Documentation at/docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!--Editable User database that can also is used by
Userdatabaserealm to authenticate users
-->
<resource name= "Userdatabase" auth= "Container"
Type= "Org.apache.catalina.UserDatabase"
description= "User database" can be updated and saved "
factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"
Pathname= "Conf/tomcat-users.xml"/>
<resource name= "Userdatabase" auth= "Container"
Type= "Org.apache.catalina.UserDatabase"
description= "User database" can be updated and saved "
factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"
Pathname= "Conf/tomcat-users.xml"/>


<resource auth= "Container"
description= "DB Connection"
Driverclass= "Oracle.jdbc.driver.OracleDriver"
Maxpoolsize= "20"
Minpoolsize= "5"
Acquireincrement= "5"
Maxidletime= "300"
Idleconnectiontestperiod= "60"
Automatictesttable= "Test"
acquireretryattempts= "30"
Breakafteracquirefailure= "true"
Name= "Jdbc/amodmondbsource"
User= "Amod"
Password= "AMODDB"
factory= "Org.apache.naming.factory.BeanFactory"
Type= "Com.mchange.v2.c3p0.ComboPooledDataSource"
Jdbcurl= "Jdbc:oracle:thin:@10.111.0.108:1521:orcl"/>


<resource auth= "Container"
description= "DB Connection"
Driverclass= "Oracle.jdbc.driver.OracleDriver"
Maxpoolsize= "20"
Minpoolsize= "5"
Acquireincrement= "5"
Maxidletime= "300"
Idleconnectiontestperiod= "60"
Automatictesttable= "Test"
acquireretryattempts= "30"
Breakafteracquirefailure= "true"
Name= "Jdbc/ddamodmondbsource"
User= "Ddamod"
Password= "DDAMODDB"
factory= "Org.apache.naming.factory.BeanFactory"
Type= "Com.mchange.v2.c3p0.ComboPooledDataSource"
Jdbcurl= "Jdbc:oracle:thin:@10.111.0.108:1521:orcl"/>


</GlobalNamingResources>


The second step is to find the context.xml of Tomcat, and add a ResourceLink node under the context node to reference the data source configured in the first step

<!--the contents of this file is loaded for each Web application-->
<Context>
<!--Default set of monitored resources. If One of these changes, the-->
<!--Web application'll be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!--uncomment this to disable session persistence across Tomcat restarts-->
<!--
<manager pathname= ""/>
-->


<resourcelink name= "Jdbc/amodmondbsource" global= "Jdbc/amodmondbsource" type= "Javax.sql.DataSource"/>
<resourcelink name= "Jdbc/ddamodmondbsource" global= "Jdbc/ddamodmondbsource" type= "Javax.sql.DataSource"/>
</Context>


The third step is to refer to the configured data source in the project

Amoddb.jndi.name=java\:comp/env/jdbc/amodmondbsource
Ddamoddb.jndi.name=java\:comp/env/jdbc/ddamodmondbsource
Root.jndi.name=java\:comp/env/jdbc/amodmondbsource
Null.jndi.name=java\:comp/env/jdbc/datasourcedb

Related Article

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.