pom.xml
添加 spring-cloud-config-server
依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
Application
通过 @EnableConfigServer` 注解,开启配置服务功能
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
bootstrap.yml
增加 Config 相关配置,并设置端口号为:8888
spring:
application:
name: hello-spring-cloud-config
cloud:
config:
label: master
server:
git:
uri: https://github.com/***/spring-cloud-config
search-paths: respo
username:
password:
server:
port: 8888
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
相关配置说明,如下:
spring.cloud.config.label
: 配置仓库的分支spring.cloud.config.server.git.uri
:配置 Git 仓库地址spring.cloud.config.server.git.search-paths
: 配置仓库路径(存放配置文件的目录)spring.cloud.config.server.git.username
: 访问 Git 仓库的账号sping.cloud.config.server.git.password
:访问 Git 仓库的密码