Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.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
Java can';t从spring云配置服务器接收值_Java_Spring_Spring Boot_Github_Spring Cloud Config - Fatal编程技术网

Java can';t从spring云配置服务器接收值

Java can';t从spring云配置服务器接收值,java,spring,spring-boot,github,spring-cloud-config,Java,Spring,Spring Boot,Github,Spring Cloud Config,使用带有Github repo的spring云配置服务器时,使用@Value(${fanout.exchange})注释初始化失败。 我得到: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'queue' defined in class path resource [com/eloomina/dataCollector/rabbitMQ/RabbitConfigura

使用带有Github repo的spring云配置服务器时,使用@Value(${fanout.exchange})注释初始化失败。 我得到:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'queue' defined in class path resource [com/eloomina/dataCollector/rabbitMQ/RabbitConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.amqp.core.Queue]: Factory method 'queue' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.rabbitConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'fanout.exchange' in value "${fanout.exchange}"
这两个类在pom.xml上都有spring云配置。configServer用@EnableConfigServer注释。github repo中的我的文件名为dataCollector.properties

RabbitConfiguration类:

@Configuration
@RefreshScope
public class RabbitConfiguration {
    @Value("${fanout.exchange}")
    private String rawDataExchange;
    @Value("${queue.name}")
    private String queueName;
    @Bean
    Queue queue() {
        return new Queue(queueName, true);
    }
    @Bean
    FanoutExchange exchange() {
        return new FanoutExchange(rawDataExchange);
    }
    @Bean
    Binding binding(Queue queue, FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
}
我的配置服务器application.properties:

server.port=8888
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
spring.application.name=configServer
spring.cloud.config.server.git.uri=https://github.com/eLoomina/configFiles
spring.cloud.config.server.git.username=xxxxxx
spring.cloud.config.server.git.password=xxxxxx
spring.application.name=dataCollector 
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
我的客户端bootstrap.properties:

server.port=8888
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
spring.application.name=configServer
spring.cloud.config.server.git.uri=https://github.com/eLoomina/configFiles
spring.cloud.config.server.git.username=xxxxxx
spring.cloud.config.server.git.password=xxxxxx
spring.application.name=dataCollector 
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
github repo包含一个文件:dataCollector.properties:


您知道为什么dataCollector服务无法从配置服务器获取fanout.exchange吗?

您的文件是在spring上下文中加载的吗?您是否可以在日志中看到文件,如下所示:

信息1234---[main]b.c.PropertySourceBootstrapConfiguration:定位的属性源:CompositePropertySource{name='demoService', propertySources=[MapPropertySource{name='configClient'}, MapPropertySource {name=''}]}


您的文件是在spring上下文中加载的吗?您是否可以在日志中看到文件,如下所示:

信息1234---[main]b.c.PropertySourceBootstrapConfiguration:定位的属性源:CompositePropertySource{name='demoService', propertySources=[MapPropertySource{name='configClient'}, MapPropertySource {name=''}]}


我可以访问localhost:8888/dataCollector/default。你是说在我的配置服务器中?还是在客户端?(dataCollector)?我的意思是在启动客户机时,在客户机中加载的是配置文件。因为除非加载配置文件,否则@Value无法将该字段绑定到属性,因为该属性在spring上下文中不可用。我在客户端日志中看不到该文件。我猜问题在于从配置服务器获取该文件。您能否将配置文件移动到客户端资源目录的本地并包含在spring上下文中,然后查看它是否有效?如果是,则问题与配置服务器有关。此外,请尝试将所有配置属性移动到bootstrap.properties,而不是application.properties spring.cloud.config.server.git.uri=spring.cloud.config.server.git.password=xxxxxx。我可以访问localhost:8888/dataCollector/default。你是说在我的配置服务器中?还是在客户端?(dataCollector)?我的意思是在启动客户机时,在客户机中加载的是配置文件。因为除非加载配置文件,否则@Value无法将该字段绑定到属性,因为该属性在spring上下文中不可用。我在客户端日志中看不到该文件。我猜问题在于从配置服务器获取该文件。您能否将配置文件移动到客户端资源目录的本地并包含在spring上下文中,然后查看它是否有效?如果是,则问题与配置服务器有关。此外,请尝试将所有配置属性移动到bootstrap.properties,而不是application.properties spring.cloud.config.server.git.uri=spring.cloud.config.server.git.password=xxxxxx