<?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:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
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-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- 配置和业务逻辑有关的 -->
<!-- 不扫描已由springmvc扫描的controller注解 -->
<context:component-scan
base-package="com.cenmou">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" /><!-- expression="org.springframework.stereotype.Controller"不扫控制器 -->
</context:component-scan>
<!-- 引入properties配置文件 -->
<context:property-placeholder
location="classpath:dbconfig.properties" />
<bean id="pooledDataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property> <!-- 数据库名 -->
<property name="driverClass" value="${jdbc.driverClass}"></property><!-- 数据库驱动类 -->
<property name="user" value="${jdbc.user}"></property><!-- 用户名 -->
<property name="password" value="${jdbc.password}"></property><!-- 用户密码 -->
</bean>
<!-- 和MyBatis整合 -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation"
value="classpath:mybatis-config.xml"></property>
<property name="dataSource" ref="pooledDataSource"></property> <!-- 数据源既上面的pooledDataSource-->
<!-- 指定mybatis,mapper文件的位置 -->
<property name="mapperLocations"
value="classpath:mapper/*.xml"></property>
</bean>
<!-- 扫描dao接口 -->
<mybatis-spring:scan base-package="com.cenmou.crud.dao"/>
<!-- 配置事务控制 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 控制数据源 -->
<property name="dataSource" ref="pooledDataSource"></property>
</bean>
<!-- 使用xml配置形式的事务 -->
<aop:config>
<aop:pointcut expression="execution(* com.cenmou.crud.service..*(..))" id="txPoint"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
</aop:config>
<!-- 配置事务增强 事务如何切入 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
<!-- 以get开始的所有方法-->
<tx:method name="get*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- spring 配置文件(数据源、mybatis整合、事务控制) -->
</beans>