yzt
2023-09-27 726603df43447f8cfedfeaae4267209adbd01699
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?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.da.util.SpringContextHolder" lazy-init="false" />
    <!--  <context:property-placeholder ignore-unresolvable="true" location="classpath:jdbc.properties"         />  -->
     
    <bean id="propertyConfigurer"   class="com.da.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.da">
        <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.da.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.da.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">  -->
    <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.da.util.MyExceptionHandler" />
 
</beans>