Spring Data JPA整合Redis缓存的配置
时间:2017-10-16 19:22:09
收藏:0
阅读:1665
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"); }
评论(0)