繁体   English   中英

无法从Spring Cloud配置服务器接收值

[英]can't receive values from spring cloud config server

在通过Github存储库使用spring-cloud-config服务器时,使用@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-cloud-config。 configServer带有@EnableConfigServer注释。 我在github存储库中的文件名为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

我的客户bootstrap.properties:

spring.application.name=dataCollector 
spring.cloud.config.uri=http://localhost:8888
management.security.enabled=false
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka

github存储库包含一个文件:dataCollector.properties:

s

pring.devtools.restart.enabled = false

eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka


server.port=8081
spring.application.name=dataCollector

##MONGO:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=accounts



management.server.port: 9001

## RABBITMQ
queue.name: rawDataQueue
fanout.exchange: rawdata-exchange
spring.rabbitmq.host: localhost
spring.rabbitmq.port: 5672
spring.rabbitmq.username: guest
spring.rabbitmq.password: guest

##LOGGING:
logging.file=dataCollector.log

有什么想法为什么dataCollector服务不会从配置服务器获取fanout.exchange?

您的文件是否在Spring环境中加载? 您可以在日志中看到如下所示的文件:

INFO 1234 --- [main] bcPropertySourceBootstrapConfiguration:定位的属性源:CompositePropertySource {name ='demoService',propertySources = [MapPropertySource {name ='configClient'},MapPropertySource {name =' https://github.com/demo-configuration /application.properties '}]}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM