0

I'm not unable to get value (Product-Service.yml) on the config server. When running the Config-Client (OrderServerApplication) application then shows an error.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderServerApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'test.name' in value "${test.name}"

Config-Server(application.yml)

    server:
  port: 3333
  
spring:
  application:
    name: Configuration-Service
 
 #Git Configuration properties
  cloud:
    config:
      server:
        git:
          uri: https://github.com/javabootstar/microservice-config-server.git
          username: root
          password: root
          clone-on-start: true
          default-label: main

Pom.xml

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>

OrderServerApplication.class

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class OrderServerApplication {
    
    @Value("${test.name}")
    private String name;
    
    public static void main(String[] args) {
        SpringApplication.run(OrderServerApplication.class, args);
    }
    
    @GetMapping("/name")
    public String name() {
        return name;
    }

}

Config-Client(application.yml)

    #Server Port
server:
  port: 2222
  
#Project Name
spring:
  application:
    name: Order-Service
  config:
    import: optional:configserver:http://localhost:3333
  datasource:
    username: admin
    password: root
    url: jdbc:mysql://localhost:3306/testdb
    driver-class-name: com.mysql.cj.jdbc.Driver
    
#Eureka Properties
eureka:
  instance:
    instance-id: ${spring.application.name}:${random.uuid}

Config-Client(bootstrap.yml)

spring:
  cloud:
    config:    
      uri:
      - http://localhost:3333
      fail-fast: true
      
management:
  endpoints:
    web:
      exposure:
        include: '*'

Git Store File (Product-Service.yml)

test:
  name:test

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy