一、创建服务注册中心springcloud_configserver
1 创建application.properties文件
spring.application.name=config-server server.port=8000 spring.cloud.config.server.git.uri=https://gitee.com/baekhyunne/Config.git spring.cloud.config.server.git.searchPaths=respo spring.cloud.config.label=master spring.cloud.config.server.git.username= spring.cloud.config.server.git.password=
2 创建启动程序类
@SpringBootApplication @EnableConfigServer public class StartServer { public static void main(String[] args) { SpringApplication.run(StartServer.class,args); } }
3 运行效果
二 、创建客户端项目springcloud_configclient
1 创建bootstrap.propertiea文件
spring.application.name=config-client spring.cloud.config.label=master spring.cloud.config.profile=dev spring.cloud.config.uri= http://localhost:8000/ server.port=7000
2 创建ClientController类
@RestController public class ClientController { @Value("${userName}") String userName; @RequestMapping("/getConfig") public String getConfig(){ return userName; } }
3 创建启动程序类
@SpringBootApplication public class StartClient { public static void main(String[] args) { SpringApplication.run(StartClient.class,args); } }
4 向git上传一个文件
5 运行效果