1
votes

I am working through a few tutorials for spring cloud and have hit a problem with my config client app. I have a Eureka server running on a Linux machine and on my Mac I have a config server which is registering correctly with the Eureka server. I generated a config client app using the spring initialiser. The dependencies I have are:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</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-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

I have a bootstrap.properties file like this:

spring.application.name=config-client-app
spring.cloud.config.discovery.enabled=true
eureka.client.serviceUrl.defaultZone=http://192.168.1.125:8761/eureka/

When the config client app starts it fails to register with the Eureka server, as it is looking for an instance running on the local machine. If I put this in the application.properties then it does register with eureka but with the name UNKNOWN.

eureka.client.serviceUrl.defaultZone=http://192.168.1.125:8761/eureka/

From this it seems that the config client app is not using the bootstrap.properties file. From what I have read by having spring-cloud-starter-config on the classpath it should look for a bootstrap.properties file at startup.

The main application class has the following annotations.

@SpringBootApplication
@EnableDiscoveryClient
@RestController

What I am trying to achieve here is for the client to ask eureka for the location of the config server and then get it's config from there.

Thanks Andrew

1
I think the bootstrap.properties are only valid for servers; the properties you listed should be placed in ordinary client's application.properties. - k-wasilewski
Not sure that is the case. Looking at this page cloud.spring.io/spring-cloud-config/reference/html/… Discovery First Bootstrap it does say that the client needs a bootstrap.properties file to locate the discovery server and then from that it can obtain the config for the client application. In my case though it is not picking up the bootstrap.properties file. - Andrew Coleman

1 Answers

2
votes

Think I have solved the problem, based upon this post here. Spring Cloud Config: client doesn't attempt to connect to the config server

I added

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

to my pom.xml and it now seems to be working as expected.