<?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:tx="http://www.springframework.org/schema/tx"
|
xmlns:aop="http://www.springframework.org/schema/aop"
|
xmlns:context="http://www.springframework.org/schema/context"
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
http://www.springframework.org/schema/tx
|
http://www.springframework.org/schema/tx/spring-tx.xsd
|
http://www.springframework.org/schema/aop
|
http://www.springframework.org/schema/aop/spring-aop.xsd
|
http://www.springframework.org/schema/context
|
http://www.springframework.org/schema/context/spring-context.xsd
|
http://www.springframework.org/schema/redis
|
http://www.springframework.org/schema/redis/spring-redis.xsd"
|
xmlns:redis="http://www.springframework.org/schema/redis">
|
|
<!--引入配置文件-->
|
<context:property-placeholder location="classpath:/redis.properties" ignore-unresolvable="true"></context:property-placeholder>
|
|
<!--redis链接密码-->
|
<bean id="redisPassword" class="org.springframework.data.redis.connection.RedisPassword">
|
<constructor-arg name="thePassword" value="${redis.password}"></constructor-arg>
|
</bean>
|
|
<!--spring-data-redis2.0以上的配置-->
|
<bean id="redisStandaloneConfiguration" class="org.springframework.data.redis.connection.RedisStandaloneConfiguration">
|
<property name="hostName" value="${redis.hostname}"/>
|
<property name="port" value="${redis.port}"/>
|
<property name="password" ref="redisPassword" />
|
<property name="database" value="${redis.database}"/>
|
</bean>
|
<!--配置jedis链接工厂 spring-data-redis2.0中
|
建议改为构造器传入一个RedisStandaloneConfiguration 单机
|
RedisSentinelConfiguration 主从复制
|
RedisClusterConfiguration 集群-->
|
<bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
|
<!--注销掉的部分为spring-data-redis2.0以下的版本配置的方式-->
|
<!-- <property name="hostName" value="${redis.hostname}"/>
|
<property name="port" value="${redis.port}"/>
|
<property name="poolConfig" ref="jedisPoolConfig"/>
|
<property name="password" value="${redis.password}" />
|
<property name="database" value="${redis.database}"/>-->
|
<!--spring-data-redis2.0以上建议获取的方式-->
|
<constructor-arg name="standaloneConfig" ref="redisStandaloneConfiguration"></constructor-arg>
|
</bean>
|
|
<!--手动设置 key 与 value的序列化方式-->
|
<bean id="keySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
|
<bean id="valueSerializer" class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
|
|
<!--配置jedis模板 -->
|
<bean id = "redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
|
<property name="connectionFactory" ref="redisConnectionFactory" />
|
<property name="keySerializer" ref="keySerializer" />
|
<property name="valueSerializer" ref="valueSerializer" />
|
<property name="hashKeySerializer" ref="keySerializer" />
|
<property name="hashValueSerializer" ref="valueSerializer" />
|
</bean>
|
|
<!--也可以StringRedisTemplate 专注于String的操作 -->
|
<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
|
<!--<property name="connectionFactory" ref="jedisConnectionFactory"></property>-->
|
<!--在StringRedisTemplate与redisTemplate不同,可以直接造构造器中传入ConnectionFactory-->
|
<constructor-arg name="connectionFactory" ref="redisConnectionFactory"></constructor-arg>
|
<property name="keySerializer" ref="keySerializer" />
|
<property name="valueSerializer" ref="valueSerializer" />
|
<property name="hashKeySerializer" ref="keySerializer" />
|
<property name="hashValueSerializer" ref="valueSerializer" />
|
</bean>
|
|
<!-- web socket 发送订阅消息 -->
|
<bean id="redisDAO" class="com.yc.im.service.RedisDAOImpl">
|
<property name="redisTemplate" ref="redisTemplate" />
|
</bean>
|
|
<!-- AI雷达监听订阅消息,并触发事件 -->
|
<bean id="listenerForWebSocket" class="com.yc.im.api.messagelistener.WebSocketMessageListener">
|
<property name="redisTemplate" ref="redisTemplate"/>
|
</bean>
|
<bean id="listenerForDataSource" class="com.yc.multiData.DataSourceMessageListener">
|
<property name="redisTemplate" ref="redisTemplate"/>
|
</bean>
|
<bean id="listenerForImageCache" class="com.yc.sdk.shopping.filter.ClearImageCacheMessageListener">
|
<property name="redisTemplate" ref="redisTemplate"/>
|
</bean>
|
<!-- 系统消息监听订阅消息,并触发事件 -->
|
<bean id="listenerForMessages" class="com.yc.sdk.WebSocketMessage.api.messagelistener.WebSocketMessageListener">
|
<property name="redisTemplate" ref="redisTemplate"/>
|
</bean>
|
<!-- 监听二维码订阅,并触发事件-->
|
<bean id="listenerForQrCodeSession" class="com.yc.phoneQRLogin.listener.WebSocketqrCodeListener">
|
<property name="redisTemplate" ref="redisTemplate"/>
|
</bean>
|
<!-- 监听二维码过期,并触发事件 -->
|
<bean id="listenerForQrCodeInvalid" class="com.yc.phoneQRLogin.listener.WebSocketqrCodeInvalidListener">
|
<property name="redisTemplate" ref="redisTemplate"/>
|
</bean>
|
|
<!-- the default ConnectionFactory -->
|
<bean id="jdkSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
|
|
<redis:listener-container >
|
<!-- the method attribute can be skipped as the default method name is "onMessage" -->
|
<redis:listener ref="listenerForWebSocket" serializer="jdkSerializer" topic="Onbus_WSMQ" />
|
<redis:listener ref="listenerForDataSource" serializer="jdkSerializer" topic="Onbus_DataSource" />
|
<redis:listener ref="listenerForImageCache" serializer="jdkSerializer" topic="Onbus_ClearImageCache" />
|
<redis:listener ref="listenerForMessages" serializer="jdkSerializer" topic="Onbus_Messages" />
|
<redis:listener ref="listenerForQrCodeSession" serializer="jdkSerializer" topic="Onbus_Qrcode" />
|
<redis:listener ref="listenerForQrCodeInvalid" serializer="jdkSerializer" topic="__keyevent@*__:expired"/>
|
</redis:listener-container>
|
|
|
|
<!--设置jedisPool链接池的配置-->
|
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
|
<!--最大连接数 -->
|
<property name="maxTotal" value="${redis.maxTotal}"/>
|
<!--最大空闲连接数 -->
|
<property name="maxIdle" value="${redis.maxIdle}"/>
|
<!--每次释放连接的最大数目 -->
|
<property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"/>
|
<!--释放连接的扫描间隔(单位:毫秒) -->
|
<property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"/>
|
<!--连接最小空闲时间(单位:毫秒) -->
|
<property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"/>
|
<!--连接空闲多久后释放,当空闲时间大于该值并且空闲连接大于最大空闲连接时直接释放连接 -->
|
<property name="softMinEvictableIdleTimeMillis" value="${redis.softMinEvictableIdleTimeMillis}"/>
|
<!--获取连接时最大等待毫秒数,如果该值小于0,则阻塞不确定的时长,默认值-1 -->
|
<property name="maxWaitMillis" value="${redis.maxWaitMillis}"/>
|
<!--在获取连接时检查连接有效性,默认为false -->
|
<property name="testOnBorrow" value="${redis.testOnBorrow}"/>
|
<!--在连接空闲时检查连接有效性,默认为false -->
|
<property name="testWhileIdle" value="${redis.testWhileIdle}"/>
|
<!--连接耗尽是否阻塞,false代表抛异常,true代表阻塞直到超时,默认为true -->
|
<property name="blockWhenExhausted" value="${redis.blockWhenExhausted}"/>
|
<property name="testOnReturn" value="${redis.testOnReturn}"/>
|
</bean>
|
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
|
<constructor-arg index="0" ref="jedisPoolConfig" />
|
<constructor-arg index="1" value="${redis.hostname}" />
|
<constructor-arg index="2" value="${redis.port}" type="int" />
|
<constructor-arg index="3" value="${redis.timeout}" type="int" />
|
<constructor-arg index="4" value="${redis.password}" />
|
</bean>
|
|
</beans>
|