【发布时间】:2019-11-26 05:12:23
【问题描述】:
使用带有 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 repo 包含一个文件: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 吗?
【问题讨论】:
标签: java spring spring-boot github spring-cloud-config