当前位置: 首页 > 知识库问答 >
问题:

无法从spring cloud配置服务器接收值

柳德义
2023-03-14

使用@value(${fanout.exchange})注释在使用带有Github Repo的spring-cloud-config服务器时初始化失败。我得到:

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 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);
    }
}
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

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吗?

共有1个答案

童花蜂
2023-03-14

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

信息1234---[main]B.C.PropertySourceBootstrapConfiguration:定位的属性源:CompositePropertySource{name='demo service',PropertySources=[MapPropertySource{name='config client'},MapPropertySource{name='https://github.com/demo-configuration/application.properties'}]}

 类似资料:
  • 我试图让一些基于PAHO的客户机使用Vert.x MQTT服务器。我试图发布到我的接收客户端订阅的测试主题。我很难从客户端发布者向客户端订阅者发送消息。 使用我在Internet上看到的真实例子,我构建了一个MQTT代理。vert.x MQTT代理代码的代码如下所示: 我很确定我在这里错过了什么,但我想不出会是什么。有人能帮我把这个弄好吗??? 提前感谢您的任何帮助或见解。

  • 我正在尝试使用Spring配置服务器和客户端加密和解密配置属性。我有Spring启动应用程序(服务器和客户端),使用服务器我有加密的密码属性,在客户端,我试图使用相同的密钥解密它,但出错了。我正在尝试启用配置服务器客户端来解密这些最初由配置服务器加密的属性。以下是我遵循的步骤: > < li> 安装全强度JCE并替换JRE lib/security中的2个策略文件 使用keytool生成密钥 向p

  • 我在ubuntu中使用sudo-apt-get安装了ApacheTomcat7。我已经使用Windows将apache tomcat 7添加到eclipse中 无法在localhost配置 /Servers/Tomcatv7.0服务器上加载Tomcat服务器配置。配置可能已损坏或不完整。 我提供的tomcat7路径是/usr/share/tomcat7

  • 我有一个示例代码如下,套接字绑定到IP10.10.88.11和端口9876。我用下面的wireshark测试了2种情况。两台电脑都在同一个子网中。 从同一PC发送UDP数据包(10.10.88.11)-UDP服务器能够接收 从另一台电脑发送UDP数据包(10.10.88.10)-UDP服务器无法接收,但Wireshark(在10.10.88.11)能够捕获数据包 我在网上搜索过,但找不到解决办法。

  • 当我试图启动SpringBoot主应用程序时,出现以下异常。为什么我会得到这个特例。 异常: Spring boot主java类

  • 我正在关注应用程序中的条目。 我有下面的spring云服务器应用程序代码。 我收到以下错误。 启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2021 02月24日01:39:52.356错误20804---[restartedMain]o.s.b.d.LoggingFailureAnalysisReporter: 应用程序无法启动 描述: