applicationContext.xml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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:context="http://www.springframework.org/schema/context"
  6. xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
  7. xmlns:tx="http://www.springframework.org/schema/tx"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
  10. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
  11. http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
  13. <!--扫描需要扫描的包-->
  14. <context:component-scan base-package="com.sf"></context:component-scan>
  15. <!--导入外部属性资源文件 db.properties-->
  16. <context:property-placeholder location="classpath:db.properties"></context:property-placeholder>
  17. <!--配置数据库连接池-->
  18. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  19. <property name="url" value="${jdbc_url}" />
  20. <property name="username" value="${jdbc_user}" />
  21. <property name="password" value="${jdbc_password}" />
  22. <property name="filters" value="stat" />
  23. <property name="maxActive" value="20" />
  24. <property name="initialSize" value="1" />
  25. <property name="maxWait" value="60000" />
  26. <property name="minIdle" value="1" />
  27. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  28. <property name="minEvictableIdleTimeMillis" value="300000" />
  29. <property name="testWhileIdle" value="true" />
  30. <property name="testOnBorrow" value="false" />
  31. <property name="testOnReturn" value="false" />
  32. <property name="poolPreparedStatements" value="true" />
  33. <property name="maxOpenPreparedStatements" value="20" />
  34. <property name="asyncInit" value="true" />
  35. </bean>
  36. <!--sqlSessionFactory-->
  37. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  38. <property name="dataSource" ref="dataSource"/>
  39. <!--mybatis核心配置-->
  40. <property name="configLocation" value="classpath:mybatis-config.xml"></property>
  41. <!--SQL MAP -->
  42. <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
  43. <!--别名-->
  44. <property name="typeAliasesPackage" value="com.sf.entity"></property>
  45. </bean>
  46. <!--配置平台事务管理器-->
  47. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  48. <property name="dataSource" ref="dataSource"/>
  49. </bean>
  50. <!--将mybatis 接口加入到IOC中-->
  51. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  52. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
  53. <property name="basePackage" value="com.sf.mapper"></property>
  54. </bean>
  55. <!--开启基于注解的声明式事物-->
  56. <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
  57. </beans>