在Spring框架中3种获得DataSource对象的方法
在Spring框架中有如下3种获得DataSource对象的方法:
1、从JNDI获得DataSource
? a)Spring JNDI数据源配置信息
<bean id="dataSource" name="code"> <Resource name="jcptDataSourceJNDI" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10" username="tysp" password="12345678" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.1.35:1521:orcl" />
要在Spring中使用DBCP连接池,需要引入commons-collections.jar、commons-dbcp.jar、commons-pool.jar
<bean id="dataSource" value="or_meal"></property> <property name="password" value="or_meal"></property> <property name="maxActive" value="100"></property> <property name="maxIdle" value="30"></property> <property name="maxWait" value="10"></property> <property name="defaultAutoCommit" value="false"></property></bean><bean id="sessionFactory" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> <prop key="show_sql">true</prop> <prop key="format_sql">true</prop> </props> </property> <property name="mappingResources"> <list></list> </property></bean>
?
?
3.?使用DriverManagerDataSource获得DataSource