SSH项目配置数据源的方法(jndi)

1、在tomcat6.0/conf/context.xml加入以下代码

<Resource name="jdbc/oracleDB" auth="Container" type="javax.sql.DataSource"  

driverClassName="oracle.jdbc.driver.OracleDriver"  
username="***" password="**" 
url="jdbc:oracle:thin:@192.168.*.*:1521:test" 
maxActive="50"   maxIdle="10" maxWait="20000" initialSize="5"  

/>


2.在项目的配置文件中applicationContext.xml文件中加入以下代码:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
<property name="jndiName"> 
<value>java:comp/env/jdbc/oracleDB</value> 
</property> 
</bean> 

3.在web.xml文件中加入以下代码

<resource-ref> 
<res-ref-name>jdbc/oracleDB</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth> 
</resource-ref> 

4在%tomcat_home%/lib/下加入数据库驱动包:

猜你喜欢

转载自ttldxl.iteye.com/blog/1293989