Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Environment.getProperty null-Spring启动Spring云_Spring_Spring Boot_Spring Cloud - Fatal编程技术网

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