nacos version:1.4.1
application.class
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })
@NacosPropertySource(dataId = "flyaway", autoRefreshed = true)
public class NacosApplicaiton {
@Value("${server.port:1}")
private int port;
@PostConstruct
public void init() {
System.out.println(port);
}
public static void main(String[] args) {
SpringApplication.run(NacosApplicaiton.class, args);
}
}
application.yml
# 正确配置:
nacos:
config:
server-addr: 127.0.0.1:8848
type: yaml
bootstrap:
enable: true
log-enable: true
data-id: flyaway
discovery:
server-addr: 127.0.0.1:8848
1. The preload configuration is not enabled

查看源码中还需要配置 nacos.config bootstrap.enable
NacosConfigApplicationContextInitializer.class
2. java.lang.IllegalArgumentException: 'value' must not be null 空指针问题

Debug 到要读取data-id, 而未能读取 NacosPropertySource 注解下data-id
NacosConfigLoader.class

在使用Nacos version 1.4.1时遇到了Spring Boot应用无法正确读取yaml配置的问题。首先,发现预加载配置未开启,解决方法是在源码中启用nacos.config.bootstrap.enable。其次,出现'java.lang.IllegalArgumentException: 'value' must not be null'的空指针异常,调试过程中发现是由于未能从NacosPropertySource注解中获取到正确的data-id导致。
3142

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



