当前位置:首页 >> 智能终端演进 >> 【Spring Boot】如何集成Redis,pcpop网

【Spring Boot】如何集成Redis,pcpop网

cpugpu芯片开发光刻机 智能终端演进 1
文件名:【Spring Boot】如何集成Redis,pcpop网 【Spring Boot】如何集成Redis 在pom.xml文件中导入spring data redis的maven坐标。 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency> 在application.yml文件中加入redis相关配置。 spring:redis:host: 192.168.xxx.xxxport: 6379password: xxxxdatabase: 0 在Bean管理中加入配置类RedisConfig。 package com.app.studypro.config;import lombok.extern.slf4j.Slf4j;import org.springframework.cache.annotation.CachingConfigurerSupport;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.data.redis.connection.RedisConnectionFactory;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.serializer.StringRedisSerializer;/*** Redis的配置信息** @author Administrator*/@Configuration@Slf4jpublic class RedisConfig extends CachingConfigurerSupport {@Beanpublic RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();log.info("Redis的KeySerializer设置为:{}", StringRedisSerializer.class);// 默认的Key序列化器为:JdkSerializationRedisSerializer// 将key的序列化器改为StringRedisSerializer,以便可以在Redis的key设置什么就显示什么,不进行转化redisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setConnectionFactory(connectionFactory);return redisTemplate;}}
协助本站SEO优化一下,谢谢!
关键词不能为空
同类推荐
«    2025年12月    »
1234567
891011121314
15161718192021
22232425262728
293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接