`
ganjuelovejava
  • 浏览: 92074 次
  • 性别: Icon_minigender_2
  • 来自: 湖南
社区版块
存档分类
最新评论

spring和ibatis集成application-system.xml

阅读更多
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


<!--1. 配置数据源 -->
    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ibatis</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>huawei</value>
</property>
    </bean>

    <!--2. 配置sqlMapClient 相当于hibernate的sessionFactory -->
    <bean id="mySqlMapClient"
        class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation"
            value="com/huawei/test/ibatis/SqlMapConfig.xml"/>
        <property name="dataSource" ref="myDataSource"/>
    </bean>

    <!--3. 配置DAO -->
    <bean id="MessageDao" class="com.huawei.test.ibatis.dao.MessageDAO">
        <property name="dataSource" ref="myDataSource"/>
<property name="sqlMapClient" ref="mySqlMapClient"/>

</bean>

    <!--4. 配置服务类 -->
    <bean id="MessageServiceImpl"
class="com.huawei.test.ibatis.service.MessageImpl">
<property name="messageDao" ref="MessageDao" />
</bean>

    <!--5. 配置事务管理器TransactionManager -->
    <bean id="myTransactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="myDataSource"/>
    </bean>

    <!--6. 配置事务代理 -->
    <bean id="abstrac"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
        abstract="true">
        <property name="transactionManager" ref="myTransactionManager"/>
        <property name="transactionAttributes">
            <props>
                <!--把CustomBuyException减去.说明它即使不是runtimeException,也会rollback-->
                <!--把CustomBuyException加上.说明它即使是runtimeException,也不会rollback-->
                <prop key="*">-DataAccessException</prop>
            </props>
        </property>
    </bean>

    <!-- 继承abstrac 方便多个service来映射 -->
    <bean id="messageService" parent="abstrac">
        <property name="target" ref="MessageServiceImpl"/>
    </bean>

</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics