spring-mybatis.xml 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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:cache="http://www.springframework.org/schema/cache"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xmlns:context="http://www.springframework.org/schema/context"
  8. xsi:schemaLocation="
  9. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  10. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  11. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  12. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
  13. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  14. http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd">
  15. <context:component-scan base-package="com.goafanti.*.service;com.goafanti.*.*.service" />
  16. <bean id="log-filter" class="com.alibaba.druid.filter.logging.Log4jFilter">
  17. <property name="resultSetLogEnabled" value="true" />
  18. </bean>
  19. <bean id="idGenerator" class="com.goafanti.core.mybatis.JDBCIdGenerator"></bean>
  20. <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  21. <property name="url" value="${jdbc.url}" />
  22. <property name="username" value="${jdbc.username}" />
  23. <property name="password" value="${jdbc.password}" />
  24. <property name="initialSize" value="${jdbc.initialSize}" />
  25. <property name="minIdle" value="${jdbc.minIdle}" />
  26. <property name="maxActive" value="${jdbc.maxActive}" />
  27. <property name="maxWait" value="${jdbc.maxWait}" />
  28. <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
  29. <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
  30. <property name="validationQuery" value="${jdbc.validationQuery}" />
  31. <property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
  32. <property name="testOnBorrow" value="${jdbc.testOnBorrow}" />
  33. <property name="testOnReturn" value="${jdbc.testOnReturn}" />
  34. <property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
  35. <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
  36. <property name="logAbandoned" value="${jdbc.logAbandoned}" />
  37. <property name="filters" value="${jdbc.filters}" />
  38. <property name="proxyFilters">
  39. <list>
  40. <ref bean="log-filter"/>
  41. </list>
  42. </property>
  43. </bean>
  44. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  45. <property name="dataSource" ref="dataSource" />
  46. <property name="configLocation" value="classpath:mybatis-config.xml"/>
  47. <property name="mapperLocations" >
  48. <list>
  49. <value>classpath:com/goafanti/common/mapper/*.xml</value>
  50. </list>
  51. </property>
  52. </bean>
  53. <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
  54. <constructor-arg index="0" ref="sqlSessionFactory" />
  55. </bean>
  56. <bean id="baseMybatisDao" class="com.goafanti.core.mybatis.BaseMybatisDao" >
  57. <property name="sqlSessionFactory" ref="sqlSessionFactory" />
  58. </bean>
  59. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  60. <property name="basePackage" value="com.goafanti.common.dao" />
  61. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  62. </bean>
  63. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  64. <property name="dataSource" ref="dataSource" />
  65. </bean>
  66. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  67. <tx:attributes>
  68. <tx:method name="publish*" rollback-for="Exception" />
  69. <tx:method name="save*" rollback-for="Exception" />
  70. <tx:method name="push*" rollback-for="Exception" />
  71. <tx:method name="add*" rollback-for="Exception" />
  72. <tx:method name="update*" rollback-for="Exception" />
  73. <tx:method name="insert*" rollback-for="Exception" />
  74. <tx:method name="create*" rollback-for="Exception" />
  75. <tx:method name="batch*" rollback-for="Exception" />
  76. <tx:method name="del*" rollback-for="Exception" />
  77. <tx:method name="init*" rollback-for="Exception" />
  78. <tx:method name="bind*" rollback-for="Exception" />
  79. <tx:method name="*" read-only="true" />
  80. </tx:attributes>
  81. </tx:advice>
  82. <aop:config proxy-target-class="true">
  83. <aop:pointcut id="myPointcut" expression="execution(* com.goafanti.*.service..*.*(..))" />
  84. <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
  85. </aop:config>
  86. <cache:annotation-driven />
  87. </beans>