cloud config
新建工程:
cloud-config-center3344
pom:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--eureka client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
yml:
server: port: 3344 spring: application: name: cloud-config cloud: config: server: git: uri: https://github.com/XXXXXX/springcloud-config.git #这里我一开始用ssh的连接,会报错Auth fail, 换成tttps连接就可以了。 search-paths: - springcloud-config force-pull: true username: XXXXXXX password: XXXXXX label: master eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:7001/eureka/ #单机版
主程序
@SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ConfigCenterMain3344 { public static void main(String[] args) { SpringApplication.run(ConfigCenterMain3344.class, args); } }
需要被访问的config:
2.测试:
访问这些配置文件:
官方文档地址:
https://cloud.spring.io/spring-cloud-config/reference/html/