数据库连接池
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@192.168.222.2:1521:db_name</value>
</property>
<property name="username">
<value>username</value>
</property>
<property name="password">
<value>mima</value>
</property>
<property name="maxActive">
<value>5</value>
</property>
<property name="initialSize">
<value>1</value>
</property>
<property name="maxWait">
<value>2000</value>
</property>
<property name="minIdle">
<value>1</value>
</property>
</bean>
Spring事务及JdbcTemplate的配置
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref bean="dataSource" />
</constructor-arg>
</bean>
公共Dao代理类
<bean id="baseDAOProxy" lazy-init="true" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
使用公共代理类
<bean id="def_xxxDAOProxy" parent="baseDAOProxy">
<property name="target">
<ref local="def_xxxDAO"/>
</property>
</bean>
把spring的上下文存起来
GlobalSpringApplicationContext.setContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext()));
不用公共代理类时
<bean id="xxxxDAO" class="com.services.dao.xxxxDAO">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<bean id="xxxxDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="xxxxDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>