Spring 数据源配置
方式一:将数据源直接配置在ApplicationContext.xml中
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:testsid" /> <property name="username" value="username" /> <property name="password" value="password" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="30" /> <property name="maxWait" value="1000" /> <property name="defaultAutoCommit" value="true" /> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="60" /> </bean>
方式二:分成两部份
1、在web工程的\webapp\META-INF\目录下创建一个context.xml文件用于配置数据连接
<?xml version="1.0" encoding="UTF-8"?> <Context path="/"> <Resource name="jdbc/intf" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@127.0.0.1:1521:testsid" username="username" password="password" maxActive="100" maxIdle="30" maxWait="1000" defaultAutoCommit="true" removeAbandoned="true" removeAbandonedTimeout="60" /> </Context>
2、在ApplicationContext.xml中引入连接池
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <!-- java:comp/env/ 为固定写法 jdbc/intf为JNDI名 --> <value>java:comp/env/jdbc/intf</value> </property> </bean>
注:方式二context.xml文件中配置的数据源也可以直接配置在tomcat的tomcat-6.0.18\conf\目录下的
context.xml或server.xml中,这样的话数据源将成为TOMCAT下的全局数据源,可供各个工程共同使用
相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30