- Structure
- pom.xml
4.0.0 com.example configuration-client 0.0.1-SNAPSHOT jar org.springframework.boot spring-boot-starter-parent 1.2.8.RELEASE UTF-8 1.8 org.springframework.cloud spring-cloud-starter-config org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-starter-parent Angel.SR4 pom import org.springframework.boot spring-boot-maven-plugin
- bootstrap.properties
spring.application.name=a-bootiful-client spring.cloud.config.uri=http://localhost:8888
- ConfigClientApplicatioin.java
package org.blot.test; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication public class ConfigClientApplication { public static void main(String[] args) { SpringApplication.run(ConfigClientApplication.class, args); } } @RefreshScope @RestController class MessageRestController { @Value("${config.client.message}") private String message; @RequestMapping("/message") String getMessage() { return this.message; } }
- result
You can find the message using the url as below.
original source : http://spring.io/guides/gs/centralized-configuration/
댓글 없음 :
댓글 쓰기