<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" 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-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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- 读取db.properties -->
<context:property-placeholder location="classpath:db.properties" />
<!-- 1.配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<!-- 数据库驱动 -->
<property name="driverClassName" value="${jdbc.driver}"></property>
<!-- 连接数据库的URL -->
<property name="url" value="${jdbc.url}"></property>
<!-- 连接数据库的用户名,密码 -->
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<!-- 最大连接数 -->
<property name="maxTotal" value="${jdbc.maxTotal}"></property>
<!-- 最大空闲连接数 -->
<property name="maxIdle" value="${jdbc.maxIdle}"></property>
<!-- 初始化连接数 -->
<property name="initialSize" value="${jdbc.initialSize}"></property>
</bean>
<!-- 4.事务管理器,依赖数据源 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 通知传播行为 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 编写aop让spring自动对目标生成代理,需要使用AspectJ的表达式 -->
<aop:config>
<!-- 切面:将切入点与通知整合 -->
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.boot_crm.core.service.*.*(..))" />
</aop:config>
<!-- 配置Mybatis工厂 -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 指定核心配置文件位置 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>
<!-- Mapper代理开发(基于MapperScannerConfigurer) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.boot_crm.dao"></property>
</bean>
<!-- 配置@Service扫描 -->
<context:component-scan base-package="com.boot_crm.core.service"></context:component-scan>
</beans>
扫描二维码,在手机上阅读!
评论 (0)