Spring uses Tomcat to connect to Oracle's database connection pool

Source: Internet
Author: User
Tags auth stack trace custom name

1. First configure the Tomcat connection pool server.xml inside (not to mention many examples of Google above)

<context path= "/datatest" docbase= "E:/datasource/webapps" debug= "1" reloadable= "true" >
<resource name= "Jdbc/name" auth= "Container" type= "Javax.sql.DataSource"/>
<resourceparams name= "Jdbc/name" >
<parameter>
<name>maxActive</name>
<!--Maximum number of DB connections in pool. Set to 0 for no limit. -->
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<!--Maximum number of idle DB connections to retain in pool. Set to 0 for no limit. -->
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<!--Maximum time to wait for the A DB connection to become available in Ms. An exception is thrown if it timeout is exceeded. Set to-1 to wait indefinitely. -->
<value>10000</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<!--abandoned DB connections are removed and recycled-->
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<!--use the Removeabandonedtimeout parameter to set the number of seconds a DB connection has been idle before it is C  Onsidered abandoned. -->
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<!--Log a stack trace of the code which abandoned-->
<value>false</value>
</parameter>
<parameter>
<name>factory</name>
<!--DBCP Basic Datasource Factory-->
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>username</name>
<value>biz</value>
</parameter>
<parameter>
<name>password</name>
<value>biz</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@192.168.0.2:1521:orcl</value>
</parameter>
</ResourceParams>
</Context>

Note: Copy Oracle's JDBC connection to the Tomcat package. (Path:/common/lib/)

2. Configure the. XML configuration file for spring my name is application-context.xml (personal custom name)

<bean id= "DataSource" class= "Org.springframework.jndi.JndiObjectFactoryBean" >
<property name= "Jndiname" >
<value>java:comp/env/jdbc/name</value>
</property>
</bean>

Java:comp/env/jdbc/name This is the connection pool name that is configured in Tomcat

3. In the Web.xml inside the configuration

<resource-ref>
<description>oracle Datasource example</description>
<res-ref-name>jdbc/webbiz</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

4. Summary:

4.1. It is difficult to debug the application procedure when using

4.2 Restart Tomcat after database server reboot

4.3 After the convenience of management, connection password user name in a file inside the Web project and the database username password separated.

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.