问题描述
在使用spring clouod 2021.0.0,发现对接nacos配置中心的时候,一直无法读取到bootstarp的配置信息。
问题细究
网上搜了一下,从Spring Boot 2.4版本开始,配置文件加载方式进行了重构。
spring cloud2.4之前的源码:
package org.springframework.cloud.bootstrap;
public class BootstrapApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment();
if ((Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, true)) {
}
}
}
spring cloud2.4之后的源码:
package org.springframework.cloud.util;
public abstract class PropertyUtils {
public static boolean bootstrapEnabled(Environment environment) {
return (Boolean)environment.getProperty("spring.cloud.bootstrap.enabled", Boolean.class, false) || MARKER_CLASS_EXISTS;

本文介绍了在使用Spring Cloud 2021.0.0时遇到的配置文件加载问题,详细分析了从Spring Boot 2.4版本开始配置加载方式的改变,并提供了两种解决方案:添加bootstrap的POM依赖或设置环境变量`spring.cloud.bootstrap.enabled=true`。如果是Spring Boot项目,可添加spring-cloud-context依赖来解决。
6139

被折叠的 条评论
为什么被折叠?



