spring-context.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  9. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
  10. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
  11. default-lazy-init="true">
  12. <description>Spring Configuration</description>
  13. <!-- 加载配置属性文件 -->
  14. <context:property-placeholder ignore-unresolvable="true" location="classpath:/properties/jeeplus.properties" />
  15. <!-- 加载应用属性实例,可通过 @Value("#{APP_PROP['jdbc.driver']}") String jdbcDriver 方式引用 -->
  16. <util:properties id="APP_PROP" location="classpath:/properties/jeeplus.properties" local-override="true"/>
  17. <!-- 使用Annotation自动注册Bean,解决事物失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。 -->
  18. <context:component-scan base-package="com.jeeplus"><!-- base-package 如果多个,用“,”分隔 -->
  19. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  20. </context:component-scan>
  21. <!-- MyBatis begin -->
  22. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  23. <property name="dataSource" ref="dataSource"/>
  24. <property name="typeAliasesPackage" value="com.jeeplus.modules.**.entity.**"/>
  25. <property name="typeAliasesSuperType" value="com.jeeplus.core.persistence.BaseEntity"/>
  26. <property name="mapperLocations" value="classpath*:com/jeeplus/modules/**/*Mapper.xml"/>
  27. <property name="configLocation" value="classpath:/mybatis/mybatis-config.xml"></property>
  28. <property name="configurationProperties">
  29. <props>
  30. <prop key="dual">${jdbc.dual}</prop>
  31. </props>
  32. </property>
  33. </bean>
  34. <!-- 扫描basePackage下所有以@MyBatisMapper注解的接口 -->
  35. <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  36. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  37. <property name="basePackage" value="com.jeeplus"/>
  38. <property name="annotationClass" value="com.jeeplus.core.persistence.annotation.MyBatisMapper"/>
  39. </bean>
  40. <!-- 定义事务 -->
  41. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  42. <property name="dataSource" ref="dataSource" />
  43. </bean>
  44. <!-- 配置 Annotation 驱动,扫描@Transactional注解的类定义事务 -->
  45. <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
  46. <!-- MyBatis end -->
  47. <!-- 配置 JSR303 Bean Validator 定义 -->
  48. <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
  49. <!-- 计划任务配置,用 @Service @Lazy(false)标注类,用@Scheduled(cron = "0 0 2 * * ?")标注方法 -->
  50. <task:executor id="executor" pool-size="10"/> <task:scheduler id="scheduler" pool-size="10"/>
  51. <task:annotation-driven scheduler="scheduler" executor="executor" proxy-target-class="true"/>
  52. <!-- 数据源配置, 使用 BoneCP 数据库连接池 -->
  53. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
  54. <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
  55. <property name="driverClassName" value="${jdbc.driver}" />
  56. <!-- 基本属性 url、user、password -->
  57. <property name="url" value="${jdbc.url}" />
  58. <property name="username" value="${jdbc.username}" />
  59. <property name="password" value="${jdbc.password}" />
  60. <!-- 配置初始化大小、最小、最大 -->
  61. <property name="initialSize" value="${jdbc.pool.init}" />
  62. <property name="minIdle" value="${jdbc.pool.minIdle}" />
  63. <property name="maxActive" value="${jdbc.pool.maxActive}" />
  64. <!-- 配置获取连接等待超时的时间 -->
  65. <property name="maxWait" value="60000" />
  66. <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
  67. <property name="timeBetweenEvictionRunsMillis" value="60000" />
  68. <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
  69. <property name="minEvictableIdleTimeMillis" value="300000" />
  70. <property name="validationQuery" value="${jdbc.testSql}" />
  71. <property name="testWhileIdle" value="true" />
  72. <property name="testOnBorrow" value="false" />
  73. <property name="testOnReturn" value="false" />
  74. <!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用)
  75. <property name="poolPreparedStatements" value="true" />
  76. <property name="maxPoolPreparedStatementPerConnectionSize" value="20" /> -->
  77. <!-- 配置监控统计拦截的filters -->
  78. <property name="filters" value="stat" />
  79. </bean>
  80. <!-- 声明任务工厂 -->
  81. <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  82. <property name="dataSource" ref="dataSource" />
  83. <property name="configLocation" value="classpath:/properties/quartz.properties" />
  84. </bean>
  85. </beans>