Spring-Cloud-Config没有得到属性

问题描述 投票:1回答:1

因为收到此错误,我无法创建属性:

org.springframework.beans.factory.BeanCreationException:创建名为'configClient'的bean时出错:注入自动连接的依赖项失败;嵌套异常是java.lang.IllegalArgumentException:无法解析值“$ {user.role}”中的占位符'user.role'

我正在关注本教程:

http://www.baeldung.com/spring-cloud-configuration

我在用

@Value("${user.role}")

@Value("${user.role:}")

不会获取任何信息。

spring runtime-error spring-cloud spring-cloud-config
1个回答
0
投票

我在尝试本教程时遇到了同样的问题。似乎客户端无法实现服务器来解析属性'user.role',在我的情况下,错误是错误的属性:

spring.application.name: config-client

您可以检查服务器的配置,如果您可以使用configs访问您的github仓库。在服务器运行时,如下所示:

curl http://root:s3cr3t@localhost:9090/config-client/development/master                                                                                                                                                                         [13:26:43]
{"name":"config-client","profiles":["development"],"label":"master","version":"80d048de5faa3314429a1fce1645917786da28d6","state":null,"propertySources":[{"name":"https://gitlab.com/marcosnasp/spring-config-baeldung-tutorial.git/config-client-development.properties","source":{"user.role":"Developer"}}]}%

我使用了yml配置两者,以及服务器9090的不同端口,默认情况下是客户端端口,因为我还没有在application.properties中配置8080,客户端和服务器,看起来像:

客户端配置:

bootstrap.yml

spring:
  application:
    name: config-client
  profiles:
    active: development
  cloud:
    config:
      uri: http://localhost:9090
      username: root
      password: s3cr3t
      fail-fast: true

服务器配置:

bootstrap.yml

spring:
  application:
    name: delivery-config-server
  encrypt:
    key-store:
      location: classpath:/config-server.jks
      password: my-s70r3-s3cr3t
    alias: config-server-key
    secret: my-k34-s3cr3t

application.yml:

server:
    port: 9090

spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitlab.com/marcosnasp/spring-config-baeldung-tutorial.git
          timeout: 10
          clone-on-start: true
  security:
    user:
      name: root
      password: s3cr3t
© www.soinside.com 2019 - 2024. All rights reserved.