applicationContext.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  4. xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
  6. default-lazy-init="true">
  7. <description>Spring公共配置</description>
  8. <!-- 定义受环境影响易变的变量 -->
  9. <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  10. <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
  11. <property name="ignoreResourceNotFound" value="true" />
  12. <property name="locations">
  13. <list>
  14. <!-- 标准配置 -->
  15. <value>classpath*:/application.properties</value>
  16. <!-- 集群中节点配置 -->
  17. <value>classpath*:/application.cluster.properties</value>
  18. <!-- 本地开发环境配置 -->
  19. <value>classpath*:/application.local.properties</value>
  20. <!-- 服务器生产环境配置 -->
  21. <value>classpath*:/application.server.properties</value>
  22. </list>
  23. </property>
  24. </bean>
  25. <!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
  26. <context:component-scan base-package="com.pentair.showcase" />
  27. <!-- 以静态变量保存ApplicationContext -->
  28. <bean class="org.springside.modules.utils.spring.SpringContextHolder" lazy-init="false" />
  29. <!-- 数据源配置,使用应用内的DBCP数据库连接池 -->
  30. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  31. <!-- Connection Info -->
  32. <property name="driverClassName" value="${jdbc.driver}" />
  33. <property name="url" value="${jdbc.url}" />
  34. <property name="username" value="${jdbc.username}" />
  35. <property name="password" value="${jdbc.password}" />
  36. <property name="defaultAutoCommit" value="false" />
  37. <!-- Connection Pooling Info -->
  38. <property name="maxIdle" value="5" />
  39. <property name="maxActive" value="40" />
  40. <property name="timeBetweenEvictionRunsMillis" value="3600000" />
  41. <property name="minEvictableIdleTimeMillis" value="3600000" />
  42. </bean>
  43. <!-- quartz使用的数据源配置 -->
  44. <bean id="quartzDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  45. <property name="driverClassName" value="${jdbc.driver}" />
  46. <property name="url" value="${jdbc.url}" />
  47. <property name="username" value="${jdbc.username}" />
  48. <property name="password" value="${jdbc.password}" />
  49. </bean>
  50. <!-- Hibernate配置 -->
  51. <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  52. <property name="dataSource" ref="dataSource" />
  53. <property name="namingStrategy">
  54. <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
  55. </property>
  56. <property name="hibernateProperties">
  57. <props>
  58. <prop key="hibernate.dialect">${hibernate.dialect}</prop>
  59. <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
  60. <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
  61. </props>
  62. </property>
  63. <property name="packagesToScan" value="com.pentair.showcase" />
  64. <property name="eventListeners">
  65. <map>
  66. <entry key="save-update">
  67. <list>
  68. <bean class="com.pentair.showcase.orm.hibernate.AuditListener" />
  69. <bean class="org.hibernate.event.def.DefaultSaveOrUpdateEventListener" />
  70. </list>
  71. </entry>
  72. </map>
  73. </property>
  74. </bean>
  75. <!-- 事务管理器配置, Hibernate单数据源事务 -->
  76. <bean id="defaultTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  77. <property name="sessionFactory" ref="sessionFactory" />
  78. </bean>
  79. <!-- 另一个事务管理器, Jdbc单数据源事务 -->
  80. <bean id="quartzTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  81. <property name="dataSource" ref="quartzDataSource" />
  82. </bean>
  83. <!-- 使用annotation定义事务 -->
  84. <tx:annotation-driven transaction-manager="defaultTransactionManager" proxy-target-class="true" />
  85. </beans>