spring常见配置

数据库连接池

 <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>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

peihexian

你的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值