Eclipse +tomcat Configuring Jndi data sources

Source: Internet
Author: User

The following are the steps for a specific configuration:

1. First configure the Jndi data source under Tomcat. The specific storage directory Apache-tomcat-7.0.59\conf\catalina\localhost

Osh.xml

<?xml version= ' 1.0 ' encoding= ' utf-8 '? ><context docbase= "G:\sbwork\oshome\WebContent" reloadable= "false" Path= "/osh" >   <resource name= "Jdbc/osh" auth= "Container" type= "Javax.sql.DataSource"         driverclassname = "Oracle.jdbc.driver.OracleDriver"        url= "jdbc:oracle:thin:@ (description= (address_list = (address= (protocol= TCP) (Host=localhost) (port=1521))) (Connect_data= (SERVICE_NAME=ORCL) (server=dedicated))) "         validationquery=" Select 0 from DUAL "        username=" Olay "         password=" 123456 "        maxactive=" [         maxidle=] "maxwait="         10000 "        removeabandoned=" true "         removeabandonedtimeout="/> </Context>

(2) The database driver jar is placed in the Lib directory in the Tomcat installation file.


(3) Spring Applicationcontext.xml is configured in DataSource:

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

Note that java:comp/env must be added to the Vlaue attribute, followed by the name of resource in servers


(4) Web. XML (This step is to be fitted to the Eclipse project, otherwise the data source cannot be found)

<resource-ref><description>oracle connection</description><res-ref-name>jdbc/osh</ Res-ref-name><res-type>javax.sql.datasource</res-type><res-auth>container</res-auth ></resource-ref>


In the configuration process, I encountered the following issues, now posted out, share.

The same configuration, the same method. MyEclipse project started normally, but Eclipse project start error, wrong into the following:

Org.springframework.beans.factory.BeanCreationException:Error creating Bean with Name ' oshdatasource ' defined in ServletContext resource [/osh/config/osh-servlet.xml]: Invocation of Init method failed; Nested exception is Javax.naming.NameNotFoundException:Name [Jdbc/osh] are not bound in this Context. Unable to find [JDBC].

The error is clearly that Jdbc/oshcannot be found, resulting in a data source not being obtained. Very depressed is myclipse under no problem. Tangled for a long time, finally found the problem. a jndi data source that is not in the Eclipse environment in Tomcat . So Add the following code to the Web. xml file

<resource-ref><description>oracle connection</description><res-ref-name>jdbc/osh</ Res-ref-name><res-type>javax.sql.datasource</res-type><res-auth>container</res-auth ></resource-ref>

This will allow you to findTomcatdata source, the problem is solved.

Eclipse +tomcat Configuring Jndi data sources

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.