question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show example config when using spring.cloud.config.server.bootstrap

See original GitHub issue

Dear Spring-Boot-Team,

I try to build an spring-boot application with an embedded config-server like descriped here in the spring documentation (http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_embedding_the_config_server). My point is that I would like that the property values are also loaded while startup of my application and I thougt I can do that with setting the spring.cloud.config.server.bootstrap=true property.

But I need to call before the refresh method, before my rest controller returns the correct Hello World Message. After starting the default values are returned.

After Startup

$ curl http://localhost:8080/hello/world
Message: default default!

Refresh Scope

 $ curl -X POST http://localhost:8080/refresh
["prop2","prop1"]

After Scope Refresh

$ curl http://localhost:8080/hello/world
Message: Hello World!

My question is there a way to load them while startup, or is this behaviour like expected from your side? Or do I have overread something what still needs to do / configure!?

Many thx

Tommy Ziegler

My embedded Spring-Cloud-Server Project

pom.xml

...
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.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-web</artifactId>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-security</artifactId>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    ...
</dependencies>
...

HelloWorldApplication.java

@SpringBootApplication
@EnableConfigServer
public class HelloWorldApplication {

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

HelloWorldController.java

@RestController
@RequestMapping("/hello")
@RefreshScope
public class HelloWorldController {

    @Value("${prop1:default}") private String prop1;
    @Value("${prop2:default}") private String prop2;

    @RequestMapping(value = "/world", method = RequestMethod.GET)
    public String getHelloWorld() {
        return new StringBuilder()
                .append("Message: ")
                .append(prop1).append(" ")
                .append(prop2).append("!")
                .toString();
    }
}

application.properties

spring.application.name=root-server
spring.cloud.config.server.bootstrap=true
spring.cloud.config.server.prefix=/config
spring.cloud.config.server.git.uri= file://${user.home}/Desktop/config

Spring cloud GIT Repository file

${user.home}/Desktop/config/root-server.properties

prop1=Hello
prop2=World

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
tommyzieglercommented, Nov 23, 2015

yes when i need to embed the config-server into a application where i need to access properties.

But this is not so easy to find out from the embedded config-server documentation. I mean the fact which properties needs to define in which file. Users can think that’s enough to define it in application.properties.

But thx a lot for the information

3reactions
tommyzieglercommented, Nov 23, 2015

ok, yes I found out that the spring.application.name, spring.cloud.config.server.bootstrap=true and spring.cloud.config.server.git.uri=file://..... in bootstrap.properties needed. Maybe that would be useful information for the embedded config-server documentation.

Is that correct what I found out so far?

bootstrap.properties

spring.application.name=root-server
spring.cloud.config.server.bootstrap=true
spring.cloud.config.server.git.uri=file://${user.home}/Desktop/config

application.properties

spring.cloud.config.server.prefix=/config
Read more comments on GitHub >

github_iconTop Results From Across the Web

5. Embedding the Config Server - Spring Cloud
The Config Server runs best as a standalone application. However, if need be, you can embed it in another application. To do so,...
Read more >
Spring Cloud - Bootstrapping - Baeldung
Navigate to https://start.spring.io and select Maven and Spring Boot 2.2.x. ... Set the artifact to “config“. In the dependencies section, search ...
Read more >
java - If you have set spring.cloud.config.server.bootstrap=true ...
When I try to run this application, it does not showing any result, It only shows the default pass result (see. MessageController). or ......
Read more >
Bootstrapping — Spring Cloud Config Server - Medium
This story has the step by step instructions on how to create a config server using Spring Cloud Config for externalizing application ...
Read more >
3 Useful Tips for Developers when using Spring Cloud Config
With Spring Boot 2.4 updates, the recommended way to import properties from Spring Cloud Config Server is to use the spring.config.import property in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found