我们在springBoot项目中,通过@Value去获取,自定义在yaml中的配置时,会出现修改了nacos中的相关配置,但是服务没有动态刷新配置。
解决方法1:在启动类添加动态刷新注解,@RefreshScope
解决方法2:将配置映射到一个实体类中
@Data
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "user") //yaml中的配置前缀
public class User {
private String name;
private Integer age;
}