<?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:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
    <!-- 连接数据库 -->
   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>

   <property name="url" value="jdbc:mysql://localhost:3306/yingjiziyuan?useUnicode=true&amp;characterEncoding=utf-8"></property>
   <property name="username" value="root"></property>
   <property name="password" value="123456"></property>
   </bean>
   <!-- spring管理mybatis中的sqlSessionFactory -->
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
   <property name="dataSource" ref="dataSource"></property>
   <property name="configLocation" value="classpath:mybatis-config.xml"></property>
   </bean>
    <!-- dao接口所在的位置 -->
    <bean id="config" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.dao"></property>
    <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
    </bean>
    <!-- 配置事务类 -->
    <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="add*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <tx:method name="*" propagation="REQUIRED" read-only="true"></tx:method>
    </tx:attributes>
    </tx:advice>
    <!-- 配置切点 -->
    <aop:config>
    <aop:pointcut expression="execution(* com.service.impl.*.*(..))" id="mycut"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"/>
    </aop:config>



   <!-- 支持上传文件 -->
  <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

    <!-- 自动扫描包中的注解，依赖注入 -->
    <context:component-scan base-package="com"/>
     <!-- 开启注解功能 -->
     <mvc:annotation-driven/>
</beans>
