spring集成redis实现发布/订阅(订阅任意频道)
<!--redis配置-->
<!--连接池配置-->
<bean id="jedisPoolConfig" class="">
<property name="maxIdle" value="${}" />
<property name="minIdle" value="${}" />
<property name="maxTotal" value="${}"/>
<property name="maxWaitMillis" value="${}" />
<property name="testOnBorrow" value="${}" />
</bean>
<!--redis单例模式连接配置-->
<bean id="standaloneConfiguration" class="">
<property name="hostName" value="${}"/>
<property name="port" value="${}"/>
<property name="database" value="${}"/>
</bean>
<!--客户端连接配置-->
<bean id="clientConfiguration" class="$MutableJedisClientConfiguration" factory-method="create">
<constructor-arg name="jedisPoolConfig" ref="jedisPoolConfig" />
</bean>
<!--连接工厂配置-->
<bean id="connectionFactory" class="">
<constructor-arg name="clientConfig" ref="clientConfiguration" />
<constructor-arg name="standaloneConfig" ref="standaloneConfiguration" />
</bean>
<!--配置redis字符串句柄-->
<bean id="stringRedisTemplate" class="" >
<constructor-arg name="connectionFactory" ref="connectionFactory" />
</bean>
<!--配置监听器-->
<bean id="redisMessageListener" class="">
<property name="redisTemplate" ref="stringRedisTemplate" />
</bean>
<!--redis发布订阅-->
<bean id="redisMessageListenerContainer" class="">
<property name="connectionFactory" ref="connectionFactory" />
<!--此处不配置MessageListener,spring获取实例后自定义频道-->
</bean>
<!--redisUtil工具类-->
<!--需要将redis注入容器,使用@Autowired获取,不可直接new一个工具类,否则会获得null-->
<bean class="">
<property name="redisMessageListenerContainer" ref="redisMessageListenerContainer" />
<property name="redisMessageListener" ref="redisMessageListener" />
</bean>