ref:https://blog.csdn.net/alsyuan/article/details/73239240

1、使用org.springframework.jdbc.datasource.DriverManagerDataSource 
说明:DriverManagerDataSource建立连接是只要有请求就新建一个connection,根本没有连接池的作用。 
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
              <property name="driverClassName"><value>${jdbc.driverClassName}</value></property> 
              <property name="url"><value>${jdbc.url}</value></property> 
              <property name="username"><value>${jdbc.username}</value></property> 
              <property name="password"><value>${jdbc.password}</value></property> 

       </bean> 
3.org.apache.commons.dbcp.BasicDataSource或com.mchange.v2.c3p0.ComboPooledDataSource
说明:这是一种推荐说明的数据源配置方式,它真正使用了连接池技术 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
              <property name="driverClassName"> 
                     <value>oracle.jdbc.driver.OracleDriver</value> 
              </property> 
              <property name="url"> 
                     <value>jdbc:oracle:thin:@localhost:1521:orcl</value> 
              </property> 
              <property name="username"> 
                     <value>test</value> 
              </property> 
              <property name="password"> 
                     <value>test</value> 
              </property> 
              <property name="maxActive"> 
                     <value>255</value> 
              </property> 
              <property name="maxIdle"> 
                     <value>2</value> 
              </property> 
              <property name="maxWait"> 
                     <value>120000</value> 
              </property> 
       </bean> 

3、使用org.springframework.jndi.JndiObjectFactoryBean 或 jee命名空间引用JNDI中的数据源 

说明:JndiObjectFactoryBean 能够通过JNDI获取DataSource 

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
      <property name="jndiName"><value>java:comp/env/jdbc/roseindiaDB_local</value></property> 
<property name="resourceRef" value="true"/>//再在web.xml中定义resourceRef,并设置jdbc/roseindiaDB_local,这样可以在tomcat/conf/context.xml中定义Resource name="jdbc/roseindiaDB_local"

</bean>

或者直接jee命名空间引用

<jee:jndi-lookup id="dataSource" jndi-name="dic" />

posted on 2018-09-13 11:33  studyskill  阅读(197)  评论(0编辑  收藏  举报