遇到个很奇怪的问题,application.properties文件里面配置redis,写成spring.redis.xxx项目就报错了,必须去掉spring.的前缀,直接从redis开始写项目才能正常运行。
虽然idea提升报错,但是程序是正常的。如果加上spring的前缀,idea是没报错了,程序运行就会出错。


关注让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言问题分析:
redis.host=127.0.0.1
redis.port=6379
Java类引用配置:
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "redis")
public class RedisProperties {
private String host;
private int port;
// 省略getter和setter方法
}
使用配置:
@Autowired
private RedisProperties redisProperties;
public void someMethod() {
String host = redisProperties.getHost();
int port = redisProperties.getPort();
}
通过以上步骤可以解决配置redis时出现的问题。如果问题仍无法解决,可以考虑检查其他可能导致的原因,如版本兼容性等。