Show example config when using spring.cloud.config.server.bootstrap
See original GitHub issueDear 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:
- Created 8 years ago
- Comments:8 (4 by maintainers)
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
ok, yes I found out that the
spring.application.name
,spring.cloud.config.server.bootstrap=true
andspring.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
application.properties