-
Notifications
You must be signed in to change notification settings - Fork 1
/
applicationContext.xml
91 lines (78 loc) · 4.38 KB
/
applicationContext.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id = "DataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close" lazy-init="false">
<property name="driverClassName" value="${spring.datasource.driver-class-name}" />
<property name="url" value="${spring.datasource.url}" />
<property name="username" value= "${spring.datasource.username}"/>
<property name="password" value="${spring.datasource.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="2" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="20" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="0" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="60000" />
<property name="validationQuery"><value>SELECT 1</value></property>
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" />
<!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
</bean>
<bean id ="citySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="mapperLocations">
<list>
<value>classpath:mapper/*.xml</value>
</list>
</property>
</bean>
<bean id="cityTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="DataSource"/>
</bean>
<bean id="cityConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="citySqlSessionFactory" />
<property name="basePackage" value="org.spring.springboot.dao" />
</bean>
<bean id="cityJedisConnectionFactory" class="org.spring.springboot.utils.JedisPoolFactory">
<constructor-arg index="0" ref="jedisPoolConfig" />
<property name="host" value="${spring.redis.host}" />
<property name="port" value="${spring.redis.port}"/>
<property name="timeout" value="${spring.redis.timeout}" />
<property name="db" value="${spring.redis.database}" />
</bean>
<bean id="cityRedisTemplate" class="org.spring.springboot.utils.JedisTemplate">
<property name="jedisPoolFactory" ref="cityJedisConnectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.spring.springboot.utils.serialize.KryoRedisSerializer">
<constructor-arg index="0">
<bean class="java.lang.Class" factory-method="forName">
<constructor-arg index="0" value="org.spring.springboot.domain.CityEntity"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${spring.redis.pool.max-active}" />
<property name="maxIdle" value="${spring.redis.pool.max-idle}" />
<property name="maxWaitMillis" value="${spring.redis.pool.max-wait}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
</bean>
</beans>