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