Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

spring - Unable to fetch property value from the config server

I am learning Spring Boot v.2.3.9.RELEASE + Microservices project from here - https://www.youtube.com/watch?v=Z7A_M8HkJG0

In this example, I am unable to fetch the details from the properties file using 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);
    }

}

property-access-service

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

put (default-label: main) in yml file:

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

server: port: ${port:8888}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...