无法从配置服务器获取属性值

时间:2021-04-02 16:58:58

标签: spring spring-boot spring-cloud-config-server

我正在从这里学习 Spring Boot v.2.3.9.RELEASE + 微服务项目 - https://www.youtube.com/watch?v=Z7A_M8HkJG0

在此示例中,我无法使用 spring-cloud-config 从属性文件中获取详细信息。

spring-config-server

application.yml

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/techefx/environment-variable-repo.git

server:
  port: ${port:8888}

ConfigServerApplication.java

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }

}

属性访问服务

PropertyAccessBean.java

@Component
@ConfigurationProperties(prefix = "property-file")
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PropertyAccessBean {
    private String name;
    private String description;
}

PropertyAccessValue.java

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PropertyAccessValue {
    private String name;
    private String description;
}

PropertyAccessServiceApplication.java

@SpringBootApplication
public class PropertyAccessServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(PropertyAccessServiceApplication.class, args);
    }
}

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

将(默认标签:main)放入 yml 文件:

春天: 应用: 名称:techefx-spring-cloud-config-server 云: 配置: 服务器: 吉特: uri:https://github.com/techefx/environment-variable-repo.git 默认标签:主要

服务器: 端口:${port:8888}