spring整合redis

pom文件,注意redis-client和common-pool版本要统一


        org.apache.commons
        commons-pool2
        2.2
    
    
        org.springframework.data
        spring-data-redis
        1.6.0.RELEASE
    
     
         redis.clients 
         jedis 
         2.9.0 
    


spring配置文件



	
	
	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

	 
    
        
        
        
    
	
	 
        
            
        
        
            
        
        
            
        
        
            
        
    

测试类

@Test
	public void testJedisClientSpring() throws Exception {
		// 创建一个spring容器
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
				"classpath:spring/applicationContext-*.xml");
		// 从容器中获得JedisClient对象
		RedisTemplate redisTemplate = (RedisTemplate) applicationContext.getBean("redisTemplate");
		redisTemplate.opsForValue().set("hello","world");
		System.out.println(redisTemplate.opsForValue().get("hello"));
	}


你可能感兴趣的:(spring整合redis)