spring-mybatis.xml 4.2 KB

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