applicationContext.xml 3.2 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: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.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. <context:property-placeholder location="classpath:db.properties"/>
  16. <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
  17. <property name="driverClassName" value="${jdbc.driver}"/>
  18. <property name="url" value="${jdbc.url}"/>
  19. <property name="username" value="${jdbc.username}"/>
  20. <property name="password" value="${jdbc.password}"/>
  21. <property name="maxTotal" value="${jdbc.maxTotal}"/>
  22. <property name="maxIdle" value="${jdbc.maxIdle}"/>
  23. <property name="initialSize" value="${jdbc.initialSize}"/>
  24. </bean>
  25. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  26. <property name="dataSource" ref="dataSource"/>
  27. </bean>
  28. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  29. <tx:attributes>
  30. <tx:method name="save*" propagation="REQUIRED"/>
  31. <tx:method name="insert*" propagation="REQUIRED"/>
  32. <tx:method name="add*" propagation="REQUIRED"/>
  33. <tx:method name="create*" propagation="REQUIRED"/>
  34. <tx:method name="delete*" propagation="REQUIRED"/>
  35. <tx:method name="update*" propagation="REQUIRED"/>
  36. <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
  37. <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
  38. <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
  39. </tx:attributes>
  40. </tx:advice>
  41. <aop:config>
  42. <aop:advisor advice-ref="txAdvice" pointcut="execution(* bank.service.*.*(..))"/>
  43. </aop:config>
  44. <!-- 配置mybatis工厂 -->
  45. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  46. <!-- 注入数据源 -->
  47. <property name="dataSource" ref="dataSource"/>
  48. <!-- 指定mybatis映射文件位置 -->
  49. <property name="mapperLocations" value="classpath*:bank.dao/*Dao.xml"/>
  50. <!-- 配置mybatis PageHelper插件 -->
  51. <property name="plugins">
  52. <array>
  53. <bean class="com.github.pagehelper.PageInterceptor">
  54. <property name="properties">
  55. <value>
  56. pageSizeZero=true
  57. reasonable=true
  58. </value>
  59. </property>
  60. </bean>
  61. </array>
  62. </property>
  63. </bean>
  64. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  65. <property name="basePackage" value="bank.dao"/>
  66. </bean>
  67. <context:component-scan base-package="bank.controller"/>
  68. <context:component-scan base-package="bank.service"/>
  69. </beans>