1、pom文件添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2、配置文件application.properties中配置本地路径
#tomcat端口号
server.port=8001
#配置文件在本地
spring.profiles.active=native
#配置文件的目录
spring.cloud.config.server.native.search-locations=D:/workspace/GitHub/spring-config/config-file
3、主程序开启@EnableConfigServer注解
@EnableConfigServer
@SpringBootApplication
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
本文介绍如何使用Spring Cloud Config Server搭建配置中心。首先通过pom文件添加依赖,然后配置application.properties指定本地配置文件路径,并在主程序中启用@EnableConfigServer注解启动配置服务。
167万+

被折叠的 条评论
为什么被折叠?



