使用ssm框架開發service層所需要的配置文件(applicationContext.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:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
        <!--掃描包-->
        <context:component-scan base-package="cn.kgc.service"></context:component-scan>
        <!--引入數據源-->
        <import resource="classpath:application_dao.xml"></import>
        <!--創建SqlSessionFactory對象-->
        <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
            <!--注入數據源-->
            <property name="dataSource" ref="dataSource"></property>
        </bean>
        <!--映射文件包掃描-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="cn.kgc.dao"></property>
        </bean>

        <!--創建事物管理器對象-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <!--注入數據源-->
            <property name="dataSource" ref="dataSource"></property>
        </bean>
        <!--設置通知-->
        <tx:advice id="advice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
                <tx:method name="query*" read-only="true" propagation="SUPPORTS"/>
                <tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
                <tx:method name="*" read-only="false" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
        <!--配置切面-->
        <aop:config>
            <aop:advisor advice-ref="advice" pointcut="execution(* cn.kgc.service.impl.*.*(..))"></aop:advisor>
        </aop:config>
</beans>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM