Environment.getProperty null-Spring启动Spring云
我有一个与Environment.getProperty null-Spring启动Spring云,spring,spring-boot,spring-cloud,Spring,Spring Boot,Spring Cloud,我有一个与org.springframework.core.env.Environment自动连接的控制器 @Controller public class RegistrationController{ @Autowired (required=false) private ServiceA serviceA; @Autowired Environment env; spring引导模块配置了云配置客户端。 它在启动时从配置服务器读取配置 控制器通过其方法之一从环境中获取值 Int
org.springframework.core.env.Environment
自动连接的控制器
@Controller public class RegistrationController{
@Autowired (required=false)
private ServiceA serviceA;
@Autowired
Environment env;
spring引导模块配置了云配置客户端。
它在启动时从配置服务器读取配置
控制器通过其方法之一从环境中获取值
Integer.valueOf(env.getProperty("services.fixeddelay.val"));
但是,当我通过刷新端点刷新时,环境中的属性将为null
经过几次刷新后,它将获得值。
这样自动布线有问题吗?我应该在这里使用
@RefreshScope
?工作原理。问题在于从配置服务器加载的配置中的属性spring.application.name
。该属性是在config server中错误给出的,尽管它在classpath:bootstrap.yml
中有一个正确的值
第一次刷新后,将从环境中清除现有属性。
第二次刷新后,将加载环境值
从配置服务器属性文件中删除属性spring.application.name
,修复了该问题。现在,即使没有@RefreshScope