java spring怎么使用redis
1个回答
展开全部
1、添加spring-data-redis的jar包 2、spring配置
(1)在propertyConfigurer节点下添加redis.properties配置
classpath:redis.properties
(2)redis配置
redis使用——spring中使用jedisX
3、代码测试
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
public class JedisTemplateTest {
public static void main(String[] args){
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {'applicationContext.xml'});
RedisTemplate redisTemplate = (RedisTemplate) ContextUtils.getBean('redisTemplate');
HashOperations hashOp
(1)在propertyConfigurer节点下添加redis.properties配置
classpath:redis.properties
(2)redis配置
redis使用——spring中使用jedisX
3、代码测试
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
public class JedisTemplateTest {
public static void main(String[] args){
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {'applicationContext.xml'});
RedisTemplate redisTemplate = (RedisTemplate) ContextUtils.getBean('redisTemplate');
HashOperations hashOp
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询