<?xml version="1.0" encoding="UTF-8"?>
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
|
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
xsi:schemaLocation="
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
|
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
|
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
|
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
|
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
|
default-lazy-init="false">
|
|
<description>Spring公共配置</description>
|
<!-- 用于持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的静态方法得到spring
|
bean对象 -->
|
<bean class="com.hxzkoa.util.SpringContextHolder" lazy-init="false" />
|
<!-- <context:property-placeholder ignore-unresolvable="true" location="classpath:jdbc.properties" /> -->
|
|
<bean id="propertyConfigurer" class="com.hxzkoa.tools.EncryptablePropertyPlaceholderConfigurer" >
|
<property name="locations">
|
<list>
|
<value>classpath:jdbc.properties</value>
|
</list>
|
</property>
|
</bean>
|
|
<!-- 导入自定义的springsecurity国际化文件 -->
|
<bean id="messageSource"
|
class="org.springframework.context.support.ResourceBundleMessageSource">
|
<property name="fallbackToSystemLocale">
|
<value>false</value>
|
</property>
|
<property name="basenames">
|
<list>
|
<value>message</value>
|
<value>configs</value>
|
</list>
|
</property>
|
<property name="defaultEncoding" value="UTF-8" />
|
<!--默认为false,这样当Spring在ResourceBundle中找不到messageKey的话,就抛出NoSuchMessageException,把它设置为True,则找不到不会抛出异常,而是使用messageKey作为返回值。 -->
|
<property name="useCodeAsDefaultMessage" value="true" />
|
<!-- Default is "-1", indicating to cache forever. A value of "0" will
|
check the last-modified timestamp of the file on every message access. Do
|
not set to "0" in a production environment! -->
|
<property name="cacheSeconds" value="60" />
|
</bean>
|
<!-- 获取本地 -->
|
<bean id="localeResolver"
|
class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
|
|
<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
|
<context:component-scan base-package="com.hxzkoa">
|
<context:exclude-filter type="annotation"
|
expression="org.springframework.stereotype.Controller" /><!-- 在spring-mvc.xml中配置了 -->
|
</context:component-scan>
|
|
<!-- Jpa Entity Manager 配置 -->
|
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" lazy-init="true">
|
<property name="dataSource" ref="dataSource" />
|
<!-- <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/> -->
|
<property name="jpaVendorAdapter">
|
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
|
<property name="generateDdl" value="true"/>
|
<property name="showSql" value="true" />
|
<!-- this property forces Oracle10 on Oracle12c since Hibernete cannot guess it! -->
|
<!-- <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/> -->
|
</bean>
|
</property>
|
|
<property name="packagesToScan" value="com.hxzkoa.entities" />
|
<property name="jpaProperties">
|
<props>
|
<!-- 命名规则 My_NAME->MyName -->
|
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
|
<prop key="hibernate.generate_statistics">true</prop>
|
<prop key="hibernate.use_sql_comments">true</prop>
|
<prop key="hibernate.show_sql">true</prop>
|
<prop key="hibernate.format_sql">true</prop>
|
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory
|
</prop>
|
<prop key="net.sf.ehcache.configurationResourceName">/ehcache/ehcache-hibernate-local.xml</prop>
|
</props>
|
</property>
|
</bean>
|
|
<!-- Spring Data Jpa配置 -->
|
<jpa:repositories base-package="com.hxzkoa.repositories"
|
transaction-manager-ref="transactionManager"
|
entity-manager-factory-ref="entityManagerFactory" />
|
|
<!-- Jpa 事务配置 -->
|
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
</bean>
|
|
<!-- 使用annotation定义事务 -->
|
<tx:annotation-driven transaction-manager="transactionManager"
|
proxy-target-class="true" />
|
<!-- 数据源配置, 使用druid数据库连接池 -->
|
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
init-method="init" destroy-method="close" lazy-init="true">
|
<property name="url" value="${jdbc.url}" />
|
<property name="username" value="${jdbc.username}" />
|
<property name="password" value="${jdbc.password}" />
|
<property name="filters" value="stat" />
|
<property name="maxActive" value="20" />
|
<property name="initialSize" value="10" />
|
<property name="maxWait" value="60000" />
|
<property name="minIdle" value="1" />
|
|
<property name="timeBetweenEvictionRunsMillis" value="60000" />
|
<property name="minEvictableIdleTimeMillis" value="300000" />
|
|
<property name="validationQuery" value="SELECT 'x' FROM DUAL" />
|
<property name="testWhileIdle" value="true" />
|
<property name="testOnBorrow" value="false" />
|
<property name="testOnReturn" value="false" />
|
<property name="maxPoolPreparedStatementPerConnectionSize"
|
value="50" />
|
<!-- 打开removeAbandoned功能 -->
|
<property name="removeAbandoned" value="true" />
|
<!-- 1800秒,也就是30分钟 -->
|
<property name="removeAbandonedTimeout" value="1800" />
|
<!-- 关闭abanded连接时输出错误日志 -->
|
<property name="logAbandoned" value="true" />
|
</bean>
|
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" lazy-init="true">
|
<property name="dataSource">
|
<ref bean="dataSource" />
|
</property>
|
</bean>
|
<!-- 错误统一处理 -->
|
<bean id="exceptionHandler" class="com.hxzkoa.util.MyExceptionHandler" />
|
|
</beans>
|