SSM-springMybatis配置文件


 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:aop="http://www.springframework.org/schema/aop"
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:context="http://www.springframework.org/schema/context"
 7     xsi:schemaLocation="http://www.springframework.org/schema/beans
 8         http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
 9         http://www.springframework.org/schema/aop
10         http://www.springframework.org/schema/aop/spring-aop.xsd
11         http://www.springframework.org/schema/tx
12         http://www.springframework.org/schema/tx/spring-tx.xsd
13        http://www.springframework.org/schema/context
14        http://www.springframework.org/schema/context/spring-context.xsd">
15 <!--        掃描注解 -->
16     <context:component-scan base-package="cn.leon"></context:component-scan>
17 <!--     數據源 -->
18     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
19         <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
20         <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/user1"></property>
21         <property name="user" value="root"></property>
22         <property name="password" value="root"></property>
23     </bean>
24 <!--     sqlSessionFactory,引入數據源,配置映射文件位置 -->
25     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
26         <property name="dataSource" ref="dataSource"></property>
27         <property name="mapperLocations" value="classpath:cn/leon/mapper/*Mapper.xml"></property>
28     </bean>
29 <!--     mapperScannerConfigurer,生成代理,名稱為接口名第一個字母小寫 ,引入sqlsessionfactory-->
30     <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
31 <!--     指定基礎包的位置 -->
32         <property name="basePackage" value="cn.leon.mapper"></property>
33         <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
34     </bean>
35 <!--     聲明式事務,引入數據源 -->
36     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
37         <property name="dataSource" ref="dataSource"></property>
38     </bean>
39 <!--     開啟通知,引入聲明式事務 -->
40     <tx:advice id="txAdvice" transaction-manager="transactionManager">
41 <!--     傳播行為 -->
42         <tx:attributes>
43             <tx:method name="add*" propagation="REQUIRED"/>
44             <tx:method name="delete*" propagation="REQUIRED"/>
45             <tx:method name="update*" propagation="REQUIRED"/>
46             <tx:method name="*" propagation="SUPPORTS"/>
47         </tx:attributes>
48     </tx:advice>
49 <!--     切面 -->
50     <aop:config>
51         <aop:pointcut expression="execution(* cn.leon.service.*.*(..))" id="serviceMethod"/>
52         <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
53     </aop:config>
54 </beans>

 


免責聲明!

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



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