Spring RedisTemplate操作-xml配置(1)

<context:annotation-config />

	<!-- 把非@Controller注解的类转换为bean -->
	<context:component-scan base-package="tk.tankpao" />

	<cache:annotation-driven />

	<context:property-placeholder
		location="classpath:conf/properties/redis.properties" />

	<aop:aspectj-autoproxy proxy-target-class="true"/>

	<!-- jedis 配置 -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxIdle" value="${redis.maxIdle}" />
        <property name="maxWaitMillis" value="${redis.maxWait}" />
        <property name="maxTotal" value="${redis.maxActive}" />
        <property name="testOnBorrow" value="${redis.testOnBorrow}" />
    </bean>

    <!-- redis服务器中心 -->
    <bean id="redisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="poolConfig" ref="poolConfig" />
        <property name="port" value="${redis.port}" />
        <property name="hostName" value="${redis.host}" />
        <property name="password" value="${redis.password}" />
        <property name="timeout" value="${redis.timeout}"></property>
    </bean>

    <bean id="redisTemplate" name="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory" />
        <property name="keySerializer" ref="stringRedisSerializer" />
        <property name="valueSerializer" ref="stringRedisSerializer" />
        <property name="hashKeySerializer" ref="stringRedisSerializer" />
        <property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
        <!-- <property name="enableTransactionSupport" value="true"/> -->
    </bean>

    <bean id="jdkredisTemplate" name="jdkredisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory" />
        <property name="keySerializer" ref="jdkSerializationRedisSerializer" />
        <property name="valueSerializer" ref="jdkSerializationRedisSerializer" />
        <property name="hashKeySerializer" ref="stringRedisSerializer" />
        <property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
    </bean>

    <bean id="jacksonredisTemplate" name="jacksonredisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory" />
        <property name="keySerializer" ref="jackson2JsonRedisSerializer" />
        <property name="valueSerializer" ref="jackson2JsonRedisSerializer" />
        <property name="hashKeySerializer" ref="stringRedisSerializer" />
        <property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
    </bean>

    <bean id="stringRedisSerializer"
        class="org.springframework.data.redis.serializer.StringRedisSerializer" />
    <bean id="jackson2JsonRedisSerializer"
        class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
    <bean id="jdkSerializationRedisSerializer"
        class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />

    <!-- 配置缓存 -->
    <bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
        <constructor-arg ref="jdkredisTemplate" />
    </bean>

    <bean id="topicContainer" class="org.springframework.data.redis.listener.RedisMessageListenerContainer" destroy-method="destroy">
        <property name="connectionFactory" ref="redisConnectionFactory"/>
        <property name="messageListeners">
            <map>
                <entry key-ref="sub">
                    <bean class="org.springframework.data.redis.listener.ChannelTopic">
                        <constructor-arg value="dddchannel"/>
                    </bean>
                </entry>
                <entry key-ref="sub2">
                    <bean class="org.springframework.data.redis.listener.ChannelTopic">
                        <constructor-arg value="dddchannel"/>
                    </bean>
                </entry>
                <entry key-ref="sub3">
                    <bean class="org.springframework.data.redis.listener.ChannelTopic">
                        <constructor-arg value="cccchannel"/>
                    </bean>
                </entry>
            </map>
        </property>
    </bean>

  

时间: 2024-12-06 09:39:24

Spring RedisTemplate操作-xml配置(1)的相关文章

Spring RedisTemplate操作-List配置(4)

@Autowired @Resource(name="redisTemplate") private RedisTemplate<String, String> rt; public void flushdb(){ rt.execute(new RedisCallback<Object>() { public String doInRedis(RedisConnection connection) throws DataAccessException { con

腾讯分分彩源码带龙虎和玩法自言自语Spring依赖注入(XML配置)

至于基于XML依赖注入的过程,首先要找一个比较合适的入口,那就是getBean.那么具体是怎么实现的呢?首先写个测试方法: ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("application-common.xml","application-beans.xml","application_jdbc.xml");Object obj = app.g

Spring Boot简单xml配置集成mybatis

一.xml配置版 1.properties文件中增加的配置: mybatis.config-locations=classpath:mybatis/mybatis-config.xml mybatis.mapper-locations=classpath:mybatis/mapper/*.xml 2.mybatis-config.xml文件的配置 mapper文件里面的jdbcType重命名 <configuration> <typeAliases> <typeAlias a

IBM Mq Spring JMS 的xml配置

<?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:p="http://www.springframework.org/schema/

自言自语Spring依赖注入(XML配置)

首先说一点,因为Spring中的对象默认为单例,想要获取它默认init_lazy默认为false. 下面的图是整个流程的流程图,下面跟的源码解析就是按照这个流程来的. 至于基于XML依赖注入的过程,首先要找一个比较合适的入口,那就是getBean.那么具体是怎么实现的呢?首先写个测试方法: ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("application-common.xml",&q

Spring 中使用XML配置方式和使用注解方式实现DI

Spring容器给我们提供了很好的环境,我们只关注主要业务即可,其他的无需关注太多.今天刚学的DI DI(Dependency Injection):依赖注入 使用XML配置文件完成依赖注入 1.1普通属性的注入 创建实体类: package cn.spring.entity; import java.io.Serializable; /** * Created by accp on 2017/3/23. */ public class User implements Serializable

Spring RedisTemplate操作-发布订阅操作(8)

@Component("sub") public class Sub implements MessageListener{ @Autowired private StringRedisSerializer stringRedisSerializer; /* (非 Javadoc) * Description: * @see org.springframework.data.redis.connection.MessageListener#onMessage(org.springfra

Spring AOP基于xml配置实例

目录层级: AOP相关的几个类就是com.aop.xmltype这个报下的4个类. ICalculatorxml.java package com.aop.xmltype; /** * 加减乘除接口,用于AOP测试 * * @author Wei * */ public interface ICalculatorxml { /** * 加法 * * @param a * @param b * @return a+b */ public int doAdd(int a, int b); /** *

spring的applicationContext.xml配置SessionFactory抛异常

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <property name="dataSource" ref="dataSource"></property>  <property name="hibernateProperties&