Spring Boot集成Redis并设置密码后报错: NOAUTH Authentication required

报错信息:

bash 复制代码
io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.

Redis密码配置确认无误,但是只要使用Redis存储就报这个异常。很可能是因为配置的spring.redis.password没有被读取到。



基本依赖:

bash 复制代码
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

基本设置(application.properties):

bash 复制代码
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=your_password
spring.redis.database=0
spring.redis.timeout=3000


解决方法:

java 复制代码
@Configuration
public class RedisConfig {

    @Value("${spring.redis.password}")
    private String redisPassword;
    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.port}")
    private int redisPort;

    /**
     * 解决redis认证报错问题:io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
     *
     * @return
     */
    @Bean
    public LettuceConnectionFactory redisConnectionFactory() {
        return new LettuceConnectionFactory(
                new RedisStandaloneConfiguration(redisHost, redisPort) {{
                    setPassword(RedisPassword.of(redisPassword));
                }});
    }
}
相关推荐
qq_12498707531 天前
重庆三峡学院图书资料管理系统设计与实现(源码+论文+部署+安装)
java·spring boot·后端·mysql·spring·毕业设计
健康平安的活着1 天前
springboot+sse的实现案例
java·spring boot·后端
+VX:Fegn08951 天前
计算机毕业设计|基于springboot + vue作业管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
Li_7695321 天前
Redis —— (五)
java·redis·后端·spring
hgz07101 天前
Redis高级特性与生产环境部署
redis
JIngJaneIL1 天前
基于java+ vue办公管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
毕设源码-郭学长1 天前
【开题答辩全过程】以 基于SpringBoot的企业销售合同管理设计与实现为例,包含答辩的问题和答案
java·spring boot·后端
共享家95271 天前
Redis背景知识
数据库·redis·缓存
qq_12498707531 天前
基于协同过滤算法的在线教育资源推荐平台的设计与实现(源码+论文+部署+安装)
java·大数据·人工智能·spring boot·spring·毕业设计
WongLeer1 天前
Redis 学习笔记
redis·笔记·学习·redis缓存·redis发布订阅