applicationContext.xml 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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:util="http://www.springframework.org/schema/util"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xmlns:aop="http://www.springframework.org/schema/aop"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/util
  11. http://www.springframework.org/schema/util/spring-util.xsd
  12. http://www.springframework.org/schema/context
  13. http://www.springframework.org/schema/context/spring-context.xsd
  14. http://www.springframework.org/schema/tx
  15. http://www.springframework.org/schema/tx/spring-tx.xsd
  16. http://www.springframework.org/schema/aop
  17. http://www.springframework.org/schema/aop/spring-aop.xsd">
  18. <context:property-placeholder location="classpath:jdbc.properties"/>
  19. <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
  20. <property name="driverClassName" value="${jdbc.driverClass}"></property>
  21. <property name="url" value="${jdbc.jdbcUrl}"></property>
  22. <property name="username" value="${jdbc.user}"></property>
  23. <property name="password" value="${jdbc.password}"></property>
  24. <property name="maxTotal" value="${jdbc.maxTotal}"></property>
  25. <property name="maxIdle" value="${jdbc.maxIdle}"></property>
  26. <property name="initialSize" value="${jdbc.initialSize}"></property>
  27. </bean>
  28. <!-- 配置事务管理器,依赖于数据源 -->
  29. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  30. <!-- 注入数据源 -->
  31. <property name="dataSource" ref="dataSource"/>
  32. </bean>
  33. <!-- 使用注解来控制事务 -->
  34. <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
  35. <!-- 事务通知 -->
  36. <!-- <tx:advice id="txAdvice" transaction-manager="transactionManager">
  37. <tx:attributes>
  38. <tx:method name=""/>
  39. </tx:attributes>
  40. </tx:advice> -->
  41. <!-- 切面 -->
  42. <!-- <aop:config>
  43. <aop:advisor advice-ref="txAdvice" pointcut=""/>
  44. </aop:config> -->
  45. <!-- 配置mybatis会话工厂 -->
  46. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  47. <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  48. <!-- 注入数据源 -->
  49. <property name="dataSource" ref="dataSource"/>
  50. <!-- 指定mybatis映射文件位置 -->
  51. <property name="mapperLocations">
  52. <list>
  53. <value>classpath:mapper/*.xml</value>
  54. </list>
  55. </property>
  56. <!-- 配置pagehelper分页插件 -->
  57. <property name="plugins">
  58. <array>
  59. <bean class="com.github.pagehelper.PageInterceptor">
  60. <property name="properties">
  61. <value>
  62. pageSizeZero=true
  63. reasonable=true
  64. </value>
  65. </property>
  66. </bean>
  67. </array>
  68. </property>
  69. </bean>
  70. <!-- 配置mapper接口扫描器 -->
  71. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  72. <property name="basePackage" value="com.zhu.mapper"></property>
  73. </bean>
  74. <!-- 配置其他扫描器,如服务层-->
  75. <context:component-scan base-package="com.zhu.service"></context:component-scan>
  76. </beans>