当前位置: 代码迷 >> Web前端 >> Spring 配置文件(组合ibatis)
  详细解决方案

Spring 配置文件(组合ibatis)

热度:529   发布时间:2013-01-17 10:28:54.0
Spring 配置文件(结合ibatis)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

   <!-- <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          <property name="locations">
             <list>
                <value>WEB-INF/config/jdbc.properties</value>
             </list>
          </property>
    </bean>   -->

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
    <property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
<property name="url" value="jdbc:oracle:thin:@10.4.115.71:1521:orcl"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="20"></property>
<property name="maxWait" value="1000"></property>
</bean>
<!-- 事务配置 -->
<bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/> 
</bean>
<!-- 代理基类 -->
<bean id="txProxyTemplate" abstract="true"
       class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="do*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
    <!-- Spring 和 iBatis 的融合 -->
    <!-- 根据数据访问资源,实例化SqlMapClient对象 -->
    <bean id="baseSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
       <!-- iBatis总配置文件路径 -->
       <property name="configLocation" value="classpath:../config/SqlMapconfig.xml"/>
       <property name="dataSource" ref="dataSource"/>
    </bean>
        <!-- 创建sqlMapClientTemplate -->
    <bean id="baseSqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
       <constructor-arg>
          <ref bean="baseSqlMapClient"/>
       </constructor-arg>
    </bean>
    <!-- 实例化 BaseDAO,注入sqlMapClientTemplate对象 -->
    <bean id="baseDAO" class="com.test.dao.BaseDAO">
       <property name="sqlMapClientTemplate" ref="baseSqlMapClientTemplate"/>
    </bean>
       <!-- 实例化实体DAO,注入BaseDAO -->
    <bean id="testDao" class="com.test.dao.TestDAOImpl" parent="baseDAO"/>
     <!-- BO配置 -->
    <bean id="testBo" parent="txProxyTemplate">
       <property name="target">
          <bean class="com.test.bo.TestBOImpl">
             <property name="testDao" ref="testDao"></property>
          </bean>
       </property>
    </bean>
  <!-- action配置 -->
    <bean name="/empInformation"
          class="com.test.action.TestAction">
        <property name="testBo" ref="testBo"></property>
    </bean>
</beans>
  相关解决方案