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.
$ curl http://localhost:8080/hello/world
Message: default default!
$ curl -X POST http://localhost:8080/refresh
["prop2","prop1"]
$ 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
...
<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>
...
@SpringBootApplication
@EnableConfigServer
public class HelloWorldApplication {
public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class, args);
}
}
@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();
}
}
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
prop1=Hello
prop2=World
The values you have in application.properties should go in bootstrap.properties.
But do I need then only a bootstrap.properties? Or can I put the normal configs like spring.application.name, logging etc. also in the normal application.properties?
spring.application.name needs to be in bootstrap.properties or config server won't know what application is requesting configuration.
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?
spring.application.name=root-server
spring.cloud.config.server.bootstrap=true
spring.cloud.config.server.git.uri=file://${user.home}/Desktop/config
spring.cloud.config.server.prefix=/config
It's only useful if you use spring.cloud.config.server.bootstrap.
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
@tommyziegler Was this answer solved? I am still getting the output default default! It is not reading properties from github
@zjesse713 did you look at a125393f27bc01635f206007c00d881c6fc19489?
Most helpful comment
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