config-server(自动注册到注册中心)
导包config-server , eureka discovery
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
application.properties
spring.application.name=config-server
server.port=8888
spring.cloud.config.server.git.uri=配置git仓库地址
spring.cloud.config.server.git.searchPaths=配置仓库路径
spring.cloud.config.label=配置仓库的分支
启动类添加@EnableConfigServer注解
http请求地址和资源文件映射如下:
- /{application}/{profile}[/{label}]
- /{application}-{profile}.yml
- /{label}/{application}-{profile}.yml
- /{application}-{profile}.properties
- /{label}/{application}-{profile}.properties
config-client
导包config-client
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
application.properties改名为bootstrap.properties
spring.application.name=config-client
spring.cloud.config.label=master
spring.cloud.config.profile=dev
spring.cloud.config.uri= http://localhost:8888/
server.port=8881
笔记来源
https://blog.csdn.net/forezp/article/details/70037291