码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Data JPA整合Redis缓存的配置

时间:2017-10-16 19:22:09      阅读:1665      评论:0      收藏:0      [点我收藏+]

标签:org   代码   log   ring   classpath   get   nbsp   缓存   sse   

1. 整合的配置文件如下
    <!-- Spring整合redis -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="30"/>
    </bean>

    <!-- 配置JedisConnectionFactoryBean对象 -->
    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="localhost"/>
        <property name="port" value="6379"/>
        <property name="poolConfig" ref="poolConfig"/>
    </bean>

    <!-- 配置RedisTemplate -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="jedisConnectionFactory"/>
        <property name="keySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
        </property>
        <property name="valueSerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
        </property>
    </bean>

2. 测试代码如下
    @Test
    public void run7() throws Exception{
        ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext-redis.xml");
        RedisTemplate<String, String> t = (RedisTemplate<String, String>) ac.getBean("redisTemplate");
        t.opsForValue().set("msg", "haha");
    }

 

Spring Data JPA整合Redis缓存的配置

标签:org   代码   log   ring   classpath   get   nbsp   缓存   sse   

原文地址:http://www.cnblogs.com/qiqimu/p/7677921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!