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));
                }});
    }
}
相关推荐
Q_Q5110082855 小时前
python+django/flask的结合人脸识别和实名认证的校园论坛系统
spring boot·python·django·flask·node.js·php
Q_Q5110082855 小时前
python+django/flask的选课系统与课程评价整合系统
spring boot·python·django·flask·node.js·php
q***18845 小时前
Ubuntu上安装、使用Redis的详细教程
redis·ubuntu·bootstrap
老华带你飞5 小时前
社区养老保障|智慧养老|基于springboot+小程序社区养老保障系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序·毕设·社区养老保障
q***87605 小时前
springboot下使用druid-spring-boot-starter
java·spring boot·后端
q***69775 小时前
Y20030018基于Java+Springboot+mysql+jsp+layui的家政服务系统的设计与实现 源代码 文档
java·spring boot·mysql
q***65695 小时前
Windows环境下安装Redis并设置Redis开机自启
数据库·windows·redis
q***47435 小时前
Windows 和 Linux 系统下,如何查看 Redis 的版本号?
linux·windows·redis
q***96586 小时前
Windows版Redis本地后台启动
数据库·windows·redis
利刃大大6 小时前
【c++中间件】redis介绍 && redis-plus-plus库使用
c++·redis·中间件