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