fs-danaus
2024-03-25 1c2701eef267f3d131f4bb8baffea7404204dc51
提交 | 用户 | age
a6a76f 1 <?xml version="1.0" encoding="UTF-8"?>
F 2 <beans xmlns="http://www.springframework.org/schema/beans"
3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4        xmlns:tx="http://www.springframework.org/schema/tx"
5        xmlns:aop="http://www.springframework.org/schema/aop"
6        xmlns:context="http://www.springframework.org/schema/context"
7        xsi:schemaLocation="http://www.springframework.org/schema/beans
8        http://www.springframework.org/schema/beans/spring-beans.xsd
9        http://www.springframework.org/schema/tx 
10        http://www.springframework.org/schema/tx/spring-tx.xsd
11        http://www.springframework.org/schema/aop 
12        http://www.springframework.org/schema/aop/spring-aop.xsd
13        http://www.springframework.org/schema/context
14        http://www.springframework.org/schema/context/spring-context.xsd
15             http://www.springframework.org/schema/redis 
16             http://www.springframework.org/schema/redis/spring-redis.xsd"
17        xmlns:redis="http://www.springframework.org/schema/redis">
18
19     <!--引入配置文件-->
20     <context:property-placeholder location="classpath:/redis.properties" ignore-unresolvable="true"></context:property-placeholder>
21
22     <!--redis链接密码-->
23     <bean id="redisPassword" class="org.springframework.data.redis.connection.RedisPassword">
24         <constructor-arg name="thePassword" value="${redis.password}"></constructor-arg>
25     </bean>
26
27     <!--spring-data-redis2.0以上的配置-->
28     <bean id="redisStandaloneConfiguration" class="org.springframework.data.redis.connection.RedisStandaloneConfiguration">
29         <property name="hostName" value="${redis.hostname}"/>
30         <property name="port" value="${redis.port}"/>
31         <property name="password" ref="redisPassword" />
32         <property name="database" value="${redis.database}"/>
33     </bean>
34     <!--配置jedis链接工厂 spring-data-redis2.0中
35         建议改为构造器传入一个RedisStandaloneConfiguration  单机
36                             RedisSentinelConfiguration  主从复制
37                             RedisClusterConfiguration  集群-->
38     <bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
39         <!--注销掉的部分为spring-data-redis2.0以下的版本配置的方式-->
40         <!--  <property name="hostName" value="${redis.hostname}"/>
41           <property name="port" value="${redis.port}"/>
42           <property name="poolConfig" ref="jedisPoolConfig"/>
43           <property name="password" value="${redis.password}" />
44           <property name="database" value="${redis.database}"/>-->
45         <!--spring-data-redis2.0以上建议获取的方式-->
46         <constructor-arg name="standaloneConfig" ref="redisStandaloneConfiguration"></constructor-arg>
47     </bean>
48
49     <!--手动设置 key  与 value的序列化方式-->
50     <bean id="keySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
51     <bean id="valueSerializer" class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
52
53     <!--配置jedis模板  -->
54     <bean id = "redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
55         <property name="connectionFactory" ref="redisConnectionFactory" />
56         <property name="keySerializer" ref="keySerializer" />
57         <property name="valueSerializer" ref="valueSerializer" />
58         <property name="hashKeySerializer" ref="keySerializer" />
59         <property name="hashValueSerializer" ref="valueSerializer" />
60     </bean>
61
62     <!--也可以StringRedisTemplate  专注于String的操作  -->
63     <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
64         <!--<property name="connectionFactory" ref="jedisConnectionFactory"></property>-->
65         <!--在StringRedisTemplate与redisTemplate不同,可以直接造构造器中传入ConnectionFactory-->
66         <constructor-arg name="connectionFactory" ref="redisConnectionFactory"></constructor-arg>
67         <property name="keySerializer" ref="keySerializer" />
68         <property name="valueSerializer" ref="valueSerializer" />
69         <property name="hashKeySerializer" ref="keySerializer" />
70         <property name="hashValueSerializer" ref="valueSerializer" />
71     </bean>
72
73     <!-- web socket 发送订阅消息  -->
74     <bean id="redisDAO" class="com.yc.im.service.RedisDAOImpl">
75         <property name="redisTemplate" ref="redisTemplate" />
76     </bean>
77
78     <!-- AI雷达监听订阅消息,并触发事件 -->
79     <bean id="listenerForWebSocket" class="com.yc.im.api.messagelistener.WebSocketMessageListener">
80         <property name="redisTemplate" ref="redisTemplate"/>
81     </bean>
82     <bean id="listenerForImageCache" class="com.yc.sdk.shopping.filter.ClearImageCacheMessageListener">
83         <property name="redisTemplate" ref="redisTemplate"/>
84     </bean>
85     <!-- 系统消息监听订阅消息,并触发事件 -->
86     <bean id="listenerForMessages" class="com.yc.sdk.WebSocketMessage.api.messagelistener.WebSocketMessageListener">
87         <property name="redisTemplate" ref="redisTemplate"/>
88     </bean>
89      <!-- 监听二维码订阅,并触发事件-->
9eb57f 90     <bean id="listenerForQrCodeSession" class="com.yc.phoneQRLogin.listener.LoginQRCodeListener">
a6a76f 91         <property name="redisTemplate" ref="redisTemplate"/>
F 92     </bean>
93     <!-- 监听二维码过期,并触发事件 -->
9eb57f 94 <!--    <bean id="listenerForQrCodeInvalid" class="com.yc.phoneQRLogin.listener.WebSocketqrCodeInvalidListener">-->
X 95 <!--        <property name="redisTemplate" ref="redisTemplate"/>-->
96 <!--    </bean>-->
d3ae0a 97     <!--监听维护费支付-->
X 98     <bean id="listenerForMaintainPay" class="com.yc.MaintenanceFee.listener.MaintainPayListener">
99         <property name="redisTemplate" ref="redisTemplate"/>
100     </bean>
a6a76f 101
F 102     <!-- the default ConnectionFactory -->
103     <bean id="jdkSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
104
105     <redis:listener-container >
106         <!-- the method attribute can be skipped as the default method name is "onMessage" -->
107         <redis:listener  ref="listenerForWebSocket" serializer="jdkSerializer" topic="Onbus_WSMQ" />
108         <redis:listener  ref="listenerForImageCache" serializer="jdkSerializer" topic="Onbus_ClearImageCache" />
109         <redis:listener  ref="listenerForMessages" serializer="jdkSerializer" topic="Onbus_Messages" />
110         <redis:listener  ref="listenerForQrCodeSession" serializer="jdkSerializer" topic="Onbus_Qrcode" />
d3ae0a 111         <redis:listener  ref="listenerForMaintainPay" serializer="jdkSerializer" topic="Onbus_Maintain"/>
a6a76f 112     </redis:listener-container>
F 113
114
115
116     <!--设置jedisPool链接池的配置-->
117     <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
118         <!--最大连接数 -->
119         <property name="maxTotal" value="${redis.maxTotal}"/>
120         <!--最大空闲连接数 -->
121         <property name="maxIdle" value="${redis.maxIdle}"/>
122         <!--每次释放连接的最大数目 -->
123         <property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"/>
124         <!--释放连接的扫描间隔(单位:毫秒) -->
125         <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"/>
126         <!--连接最小空闲时间(单位:毫秒) -->
127         <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"/>
128         <!--连接空闲多久后释放,当空闲时间大于该值并且空闲连接大于最大空闲连接时直接释放连接 -->
129         <property name="softMinEvictableIdleTimeMillis" value="${redis.softMinEvictableIdleTimeMillis}"/>
130         <!--获取连接时最大等待毫秒数,如果该值小于0,则阻塞不确定的时长,默认值-1 -->
131         <property name="maxWaitMillis" value="${redis.maxWaitMillis}"/>
132         <!--在获取连接时检查连接有效性,默认为false -->
133         <property name="testOnBorrow" value="${redis.testOnBorrow}"/>
134         <!--在连接空闲时检查连接有效性,默认为false -->
135         <property name="testWhileIdle" value="${redis.testWhileIdle}"/>
136         <!--连接耗尽是否阻塞,false代表抛异常,true代表阻塞直到超时,默认为true -->
137         <property name="blockWhenExhausted" value="${redis.blockWhenExhausted}"/>
138         <property name="testOnReturn" value="${redis.testOnReturn}"/>
139     </bean>
140     <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
141         <constructor-arg index="0" ref="jedisPoolConfig" />
142         <constructor-arg index="1" value="${redis.hostname}" />
143         <constructor-arg index="2" value="${redis.port}" type="int" />
144         <constructor-arg index="3" value="${redis.timeout}" type="int" />
145         <constructor-arg index="4" value="${redis.password}" />
146     </bean>
147
148 </beans>