applicationContext-mybatis.xml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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:tx="http://www.springframework.org/schema/tx"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:mvc="http://www.springframework.org/schema/mvc"
  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/context
  11. http://www.springframework.org/schema/context/spring-context.xsd
  12. http://www.springframework.org/schema/mvc
  13. http://www.springframework.org/schema/mvc/spring-mvc.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. <!-- 配置jdbc -->
  19. <context:property-placeholder location="classpath:/properties/db.properties"/>
  20. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  21. <property name="driverClassName" value="${jdbc.driver}" />
  22. <property name="url" value="${jdbc.url}" />
  23. <property name="username" value="${jdbc.username}" />
  24. <property name="password" value="${jdbc.password}" />
  25. </bean>
  26. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  27. <property name="dataSource" ref="dataSource" />
  28. <property name="mapperLocations" value="classpath:/mapping/*.xml" />
  29. </bean>
  30. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  31. <property name="basePackage" value="com.demo.aop.dao" />
  32. <property name="sqlSessionFactory" ref="sqlSessionFactory" />
  33. </bean>
  34. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  35. <property name="dataSource" ref="dataSource" />
  36. </bean>
  37. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  38. <tx:attributes>
  39. <tx:method name="*"/>
  40. <tx:method name="find*" read-only="true"/>
  41. </tx:attributes>
  42. </tx:advice>
  43. <aop:config>
  44. <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.yuan.ehcache.service.impl.*.*(..))"/>
  45. </aop:config>
  46. <bean id="controllerAop" class="com.demo.aop.ControllerAOP" />
  47. <aop:config>
  48. <aop:aspect id="myAop" ref="controllerAop">
  49. <aop:pointcut id="target"
  50. expression="execution(* com.demo.controller.*.*(..))" />
  51. <aop:around method="handlerControllerMethod" pointcut-ref="target" />
  52. </aop:aspect>
  53. </aop:config>
  54. </beans>