yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:cache="http://www.springframework.org/schema/cache"
    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:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd    
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd    
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd    
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd    
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd    
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.2.xsd    
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.2.xsd    
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd    
        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd    
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd    
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd    
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
        http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
    <!-- 必须采用java8 -->
 
 
    <!-- 组件扫描 -->
    <context:component-scan base-package="com.yeshi.fanli">
    </context:component-scan>
    <!--配置spring 注解 -->
    <context:annotation-config />
    <!-- 默认的注解映射的支持 -->
    <mvc:annotation-driven />
    <!-- Spring AOP支持 -->
    <aop:aspectj-autoproxy proxy-target-class="true" />
 
 
    <!-- 引入配置文件 -->
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations"> <!-- PropertyPlaceholderConfigurer类中有个locations属性,接收的是一个数组,即我们可以在下面配好多个properties文件 -->
            <array>
                <value>classpath:redis.properties</value>
                <value>classpath:druid.properties</value>
                <value>classpath:mongo.properties</value>
            </array>
        </property>
    </bean>
 
    <!--异步定义推荐方式 <task:executor id="executor" pool-size="15" /> <task:scheduler 
        id="scheduler" pool-size="30" /> <task:annotation-driven executor="executor" 
        scheduler="scheduler" /> -->
 
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
    <bean
        class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
 
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        init-method="init" destroy-method="close">
 
        <!-- 基本属性 url、user、password -->
        <!-- rdsw9f61e43320loxs25.mysql.rds.aliyuncs.com -->
        <!-- <property name="url" value="jdbc:mysql://127.0.0.1:3306/ec_quan?useUnicode=true&amp;characterEncoding=utf-8" 
            /> <property name="username" value="root" /> <property name="password" value="123456" 
            /> -->
 
        <!-- gz-cdb-r13d0yi9.sql.tencentcdb.com:62929 172.16.16.17:3306 -->
 
        <property name="url" value="${druid.url}" />
        <property name="username" value="${druid.username}" />
        <property name="password" value="${druid.password}" />
 
 
 
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="${druid.initialSize}" />
        <property name="minIdle" value="${druid.minIdle}" />
        <property name="maxActive" value="${druid.maxActive}" />
 
        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="${druid.maxWait}" />
 
        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />
        <!-- 超过时间限制是否回收 -->
        <property name="removeAbandoned" value="true" />
        <!-- 超时时间;单位为秒。180秒=3分钟 -->
        <property name="removeAbandonedTimeout" value="180" />
        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />
 
        <property name="validationQuery" value="SELECT 'x'" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />
 
        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="false" />
        <property name="maxPoolPreparedStatementPerConnectionSize"
            value="20" />
        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat" />
    </bean>
 
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <!-- <prop key="hibernate.hbm2ddl.auto">false</prop> -->
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
        <!-- 自动扫描实体  -->
        <property name="packagesToScan" value="com.yeshi.fanli.entity" />
    </bean>
 
    <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation" value="classpath:mybatis-config.xml" />
        <!-- 自动扫描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:com/yeshi/fanli/mapping/**/*.xml"></property>
    </bean>
 
 
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.yeshi.fanli.dao.mybatis" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
 
 
 
 
 
 
    <!-- 事物 -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
 
    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />
 
 
 
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
 
    <mvc:resources location="/client/html/" mapping="/client/html/**" />
    <mvc:resources location="/client/css/" mapping="/client/css/**" />
    <mvc:resources location="/client/img/" mapping="/client/img/**" />
    <mvc:resources location="/client/js/" mapping="/client/js/**" />
    <mvc:resources location="/client/fonts/" mapping="/client/fonts/**" />
    <mvc:resources location="/client/layer/" mapping="/client/layer/**" />
    <mvc:resources location="/client/fan/" mapping="/client/fan/**" />
    <mvc:resources location="/client/gonglue/" mapping="/client/gonglue/**" />
    <mvc:resources location="/client/fan_client/" mapping="/client/fan_client/**" />
    <!-- <mvc:resources location="/client/" mapping="/client/**"/> -->
    <mvc:resources location="/admin/" mapping="/admin/**" />
    <mvc:resources location="/druid/" mapping="/druid/**" />
    <mvc:resources location="/client/share/" mapping="/client/share/**" />
    <mvc:resources location="/client/h5/" mapping="/client/h5/**" />
    <mvc:resources location="/client/jsp/share/css/" mapping="/client/jsp/share/css/**" />
    <mvc:resources location="/client/jsp/share/img/" mapping="/client/jsp/share/img/**" />
    <mvc:resources location="/client/jsp/share/js/" mapping="/client/jsp/share/js/**" />
    <mvc:resources location="/client/jsp/share2/css/"
        mapping="/client/jsp/share2/css/**" />
    <mvc:resources location="/client/jsp/share2/img/"
        mapping="/client/jsp/share2/img/**" />
    <mvc:resources location="/client/jsp/share2/js/" mapping="/client/jsp/share2/js/**" />
    <mvc:resources location="/client/jsp/share2/css/"
        mapping="/client/jsp/share2/css/**" />
    <mvc:resources location="/client/jsp/share2/img/"
        mapping="/client/jsp/share2/img/**" />
    <mvc:resources location="/client/jsp/share2/js/" mapping="/client/jsp/share2/js/**" />
 
    <mvc:resources location="/web/" mapping="/web/**" />
 
    <!-- 业务Bean配置 -->
    <!-- 拦截器定义 -->
    <mvc:interceptors>
        <!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
        <bean class="com.yeshi.fanli.interceptor.EncodingInterceptor" />
        <bean class="com.yeshi.fanli.interceptor.CommonInterceptor" />
    </mvc:interceptors>
 
    <task:annotation-driven scheduler="qbScheduler"
        mode="proxy" />
    <task:scheduler id="qbScheduler" pool-size="50" />
 
    <!-- 异步方法 -->
    <task:executor id="pushExecutor" pool-size="15-1000"
        queue-capacity="100" keep-alive="20" />
 
    <!-- 缓存注解支持 -->
    <cache:annotation-driven cache-manager="cacheManager" />
    <bean id="cacheManagerFactory"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml" />
    </bean>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="cacheManagerFactory" />
    </bean>
 
    <bean id="appProperty"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <array>
                <value>classpath:app.properties</value>
            </array>
        </property>
    </bean>
 
 
 
    <!-- redis连接池 -->
    <bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxActive" value="${redis.max_active}"></property>
        <property name="maxIdle" value="${redis.max_idle}"></property>
        <property name="maxWait" value="${redis.max_wait}"></property>
        <property name="testOnBorrow" value="${redis.test_on_borrow}"></property>
    </bean>
 
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="poolConfig" ref="jedisConfig"></constructor-arg>
        <constructor-arg name="host" value="${redis.addr}"></constructor-arg>
        <constructor-arg name="port" value="${redis.port}"></constructor-arg>
        <constructor-arg name="timeout" value="${redis.timeout}"></constructor-arg>
        <constructor-arg name="password" value="${redis.auth}"></constructor-arg>
    </bean>
 
    <!-- redis连接工厂 -->
    <bean id="connectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="${redis.addr}"></property>
        <property name="port" value="${redis.port}"></property>
        <property name="password" value="${redis.auth}"></property>
        <property name="poolConfig" ref="jedisConfig"></property>
    </bean>
 
    <!-- redis操作模板,这里采用尽量面向对象的模板 -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="connectionFactory" />
        <property name="keySerializer">
            <bean
                class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <property name="valueSerializer">
            <bean
                class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
    </bean>
 
 
    <!-- mongodb -->
    <mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}">
        <mongo:options connections-per-host="${mongo.connectionsPerHost}"
            threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}"
            connect-timeout="${mongo.connectTimeout}" max-wait-time="${mongo.maxWaitTime}"
            auto-connect-retry="${mongo.autoConnectRetry}" socket-keep-alive="${mongo.socketKeepAlive}"
            socket-timeout="${mongo.socketTimeout}" slave-ok="${mongo.slaveOk}"
            write-number="1" write-timeout="0" write-fsync="true"  />
    </mongo:mongo>
 
 
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
    </bean>
    <bean id="mongoDbFactory"
        class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
        <constructor-arg name="mongo" ref="mongo" />
        <constructor-arg name="databaseName" value="${mongo.dbname}" />
        <constructor-arg name="credentials" ref="userCredentials" />
        <constructor-arg name="authenticationDatabaseName"
            value="admin" />
    </bean>
    <bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials">
        <constructor-arg name="username" value="${mongo.username}" />
        <constructor-arg name="password" value="${mongo.password}" />
    </bean>
 
    <bean id="jobFactory" class="com.yeshi.fanli.job.JobFactory"></bean>
 
    <bean id="scheduler" name="Scheduler" lazy-init="false"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="jobFactory" ref="jobFactory"></property>
    </bean>
 
 
    <!-- Spring线程池 -->
    <bean id="taskExecutor"
        class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <!-- 线程池维护线程的最少数量 -->
        <property name="corePoolSize" value="100" />
        <!-- 线程池维护线程所允许的空闲时间 -->
        <property name="keepAliveSeconds" value="30000" />
        <!-- 线程池维护线程的最大数量 -->
        <property name="maxPoolSize" value="1000" />
        <!-- 线程池所使用的缓冲队列 -->
        <property name="queueCapacity" value="200" />
    </bean>
 
 
</beans>