hardik parpelli
hardik parpelli

Reputation: 13

Spring cloud config client unable to connect to server when the server is connected to git

I have spring cloud config server and client applications setup with git with following: spring boot: 2.1.17 - SNAPSHOT java: 1.8

The server works fine.

But the client is not able to fetch the server details.

It throws following error: Could not resolve placeholder 'rate' in value "${rate}" where rate is part of the properties.

server pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.17.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>m2-config-server-2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>m2-config-server-2</name>
    <description>config server 2 with git</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

server bootstrap.yaml:

---
server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/hardik92/spring-cloudconfig-tolls
#          username: uname
#          password: pwd
          search-paths:
           - 'station*'
          repos:
            perf:
              pattern:
                - "*/perf"
              uri: https://github.com/hardik92/spring-cloudconfig-tolls-perf
              search-paths:
                - 'station*'

this builds the server correctly and the call http://localhost:8888/s1rates/default works fine.

But the client fails to do so.

client pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.17.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>m2-config-client-2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>m2-config-client-2</name>
    <description>config client 2 with git</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

client bootstrap.properties:

spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=default
spring.application.name=s1rates

I saw many similar questions but none of the answers helped me. I cannot comment or add answer there since do not have enough reps.

I tried the same thing with SpringBoot 2.4 but the same error occurs.

Any help will be appreciated.

Thanks, Hardik

Upvotes: 0

Views: 1159

Answers (2)

Josu Martinez
Josu Martinez

Reputation: 348

This issue is not Spring Boot related, but Spring Cloud related. See the Spring Cloud 2020.0 Release Notes for a detailed list of breaking changes in Spring Cloud 2020.0.0-M5.

Please pay special attention to the section that specifies that bootstrap is not enabled by default. One way of enabling it is by adding the following Maven dependency to your project POM file:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

This way, whenever you fire up your Spring Cloud config server client, you should see it properly fetching the pertaining properties values from your Spring Cloud config server. Actually, your console log should specify this fact:

2020-11-30 19:17:26.800  INFO 9891 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888

In any case, hope you've already solved this problem so far ;-)

Upvotes: 5

hardik parpelli
hardik parpelli

Reputation: 13

udpated

spring.cloud.config.uri=http://localhost:8888

to

spring.cloud.config.uri=http://127.0.0.1:8888

and it worked for spring boot 2.1.17.BUILD-SNAPSHOT.

But sprint boot 2.4.0-SNAPSHOT is still failing.

Upvotes: 0

Related Questions