Eureka Config分为Config Server 和Config Client两部分。
Config Server部分:
gradle配置:
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-config-server
compile group: 'org.springframework.cloud', name: 'spring-cloud-config-server', version: '2.0.2.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-eureka-server', version: '1.4.6.RELEASE'
application.yml:
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ server: port: 8888 spring: cloud: config: server: git: uri: https://gitee.com/bensonlim/springcloud/ searchPaths: helloworldConfig application: name: config-server
EurekaconfigApplication.java
@EnableEurekaServer @EnableConfigServer @SpringBootApplication public class EurekaconfigApplication { public static void main(String[] args) { SpringApplication.run(EurekaconfigApplication.class, args); } }
Config Client部分:
application.yml:
spring:
application:
name: config-client
cloud:
config:
label: master
profile: dev
uri: http://localhost:8888/
server:
port: 8881
ConfigclientApplication.java
@SpringBootApplication @RestController public class ConfigclientApplication { public static void main(String[] args) { SpringApplication.run(ConfigclientApplication.class, args); } @Value("${hello}") String hello; @RequestMapping(value = "/hello") public String hello(){ return hello; } }
https://gitee.com/bensonlim/springcloud/tree/master/helloworldConfig
配置自动刷新:
引入acurator