spring-base.xml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:cache="http://www.springframework.org/schema/cache" xmlns:aop="http://www.springframework.org/schema/aop"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-3.2.xsd
  10. http://www.springframework.org/schema/tx
  11. http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  12. http://www.springframework.org/schema/cache
  13. http://www.springframework.org/schema/cache/spring-cache.xsd
  14. http://www.springframework.org/schema/aop
  15. http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  16. ">
  17. <!-- spring3 @value 特性加载属性文件内容 -->
  18. <context:property-placeholder location="classpath:config/system.properties" />
  19. <!-- 使用spring注解 -->
  20. <context:annotation-config />
  21. <!-- spring扫描目录 -->
  22. <context:component-scan base-package="com.persagy">
  23. <!-- 不包括@Controller -->
  24. <context:exclude-filter type="annotation"
  25. expression="org.springframework.stereotype.Controller" />
  26. </context:component-scan>
  27. <!-- 切面编程 -->
  28. <aop:aspectj-autoproxy />
  29. <!-- 数据库连接池 -->
  30. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  31. destroy-method="close">
  32. <!-- 数据库驱动 -->
  33. <property name="driverClass" value="${jdbc.driverClass}" />
  34. <!-- 数据库连接串 -->
  35. <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
  36. <!-- 用户名 -->
  37. <property name="user" value="${jdbc.user}" />
  38. <!-- 密码 -->
  39. <property name="password" value="${jdbc.password}" />
  40. <!-- 连接池维持连接数最小值 -->
  41. <property name="minPoolSize" value="${jdbc.miniPoolSize}" />
  42. <!-- 连接池维持链接数最大值 -->
  43. <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
  44. <!-- 连接池初始化链接数 -->
  45. <property name="initialPoolSize" value="${jdbc.initialPoolSize}" />
  46. <!-- 最大空闲时间,设置秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
  47. <property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
  48. <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
  49. <property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
  50. <!-- 定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
  51. <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" />
  52. <!-- 两次连接中间隔时间,单位毫秒。Default: 1000 -->
  53. <property name="acquireRetryDelay" value="${jdbc.acquireRetryDelay}" />
  54. <!-- 如果设为true那么在取得连接的同时将校验连接的有效性。Default: false -->
  55. <property name="testConnectionOnCheckin" value="${jdbc.testConnectionOnCheckin}" />
  56. <!-- c3p0将建一张名为设置表名的空表,并使用其自带的查询语句进行测试。Default: null -->
  57. <property name="automaticTestTable" value="${jdbc.automaticTestTable}" />
  58. <!--每设置秒检查所有连接池中的空闲连接。Default: 0 -->
  59. <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" />
  60. <!--当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒。Default:
  61. 0 -->
  62. <property name="checkoutTimeout" value="${jdbc.checkoutTimeout}" />
  63. </bean>
  64. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  65. <property name="dataSource" ref="dataSource" />
  66. </bean>
  67. <bean id="transactionManager"
  68. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  69. <property name="dataSource" ref="dataSource" />
  70. </bean>
  71. <tx:annotation-driven transaction-manager="transactionManager" />
  72. </beans>