applicationContext.xml 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
  8. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  9. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
  10. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
  11. <context:component-scan base-package="com.atguigu">
  12. <context:exclude-filter type="annotation"
  13. expression="org.springframework.stereotype.Controller" />
  14. </context:component-scan>
  15. <!-- Spring的配置文件,这里主要配置和业务逻辑有关的 -->
  16. <!--=================== 数据源,事务控制,xxx ================-->
  17. <context:property-placeholder location="classpath:dbconfig.properties" />
  18. <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  19. <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
  20. <property name="driverClass" value="${jdbc.driverClass}"></property>
  21. <property name="user" value="${jdbc.user}"></property>
  22. <property name="password" value="${jdbc.password}"></property>
  23. </bean>
  24. <!--================== 配置和MyBatis的整合=============== -->
  25. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  26. <!-- 指定mybatis全局配置文件的位置 -->
  27. <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  28. <property name="dataSource" ref="pooledDataSource"></property>
  29. <!-- 指定mybatis,mapper文件的位置 -->
  30. <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
  31. </bean>
  32. <!-- 配置扫描器,将mybatis接口的实现加入到ioc容器中 -->
  33. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  34. <!--扫描所有dao接口的实现,加入到ioc容器中 -->
  35. <property name="basePackage" value="com.atguigu.crud.dao"></property>
  36. </bean>
  37. <!-- 配置一个可以执行批量的sqlSession -->
  38. <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
  39. <constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
  40. <constructor-arg name="executorType" value="BATCH"></constructor-arg>
  41. </bean>
  42. <!--============================================= -->
  43. <!-- ===============事务控制的配置 ================-->
  44. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  45. <!--控制住数据源 -->
  46. <property name="dataSource" ref="pooledDataSource"></property>
  47. </bean>
  48. <!--开启基于注解的事务,使用xml配置形式的事务(必要主要的都是使用配置式) -->
  49. <aop:config>
  50. <!-- 切入点表达式 -->
  51. <aop:pointcut expression="execution(* com.atguigu.crud.service..*(..))" id="txPoint"/>
  52. <!-- 配置事务增强 -->
  53. <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
  54. </aop:config>
  55. <!--配置事务增强,事务如何切入 -->
  56. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  57. <tx:attributes>
  58. <!-- 所有方法都是事务方法 -->
  59. <tx:method name="*"/>
  60. <!--以get开始的所有方法 -->
  61. <tx:method name="get*" read-only="true"/>
  62. </tx:attributes>
  63. </tx:advice>
  64. <!-- Spring配置文件的核心点(数据源、与mybatis的整合,事务控制) -->
  65. </beans>