当前位置:   article > 正文

springcloud入门基础搭建之config_验证springcloud config是否搭建成功

验证springcloud config是否搭建成功

目录

1.工程目录

 2.github准备

 3.config-server服务端

3.1新建子项目springcloud-config-server

3.2依赖

3.3配置文件

 3.4主启动类添加@EnableConfigServer

3.5测试

4.config-client客户端

4.1新建工程springcloud-config-client

4.2依赖

4.3配置文件

 4.4编写controller

4.5测试

 传送门


1.工程目录

        springcloud-config-server为config配置中心服务端,端口为9510

        springcloud-config-client为config配置中心客户端,端口为9520

 2.github准备

        config推荐使用github,所以这里也是使用github来测试。

 3.config-server服务端

3.1新建子项目springcloud-config-server

        端口号为9510

        涉及文件如下

        

3.2依赖

        config配置中心本身也需要注册到eureka中。也可以不使用eureka

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>javax.servlet</groupId>
  8. <artifactId>servlet-api</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.springframework.cloud</groupId>
  14. <artifactId>spring-cloud-config-server</artifactId>
  15. </dependency>
  16. </dependencies>

3.3配置文件

       

  1. spring:
  2. application:
  3. name: springcloud-config-server
  4. cloud:
  5. config:
  6. server:
  7. git:
  8. uri: https://github.com/c4you/springcloud-begin.git
  9. #公共仓库,所以不需要用户名密码
  10. #username:
  11. #password:
  12. search-paths:
  13. - springcloud-config
  14. server:
  15. port: 9510
  16. eureka:
  17. instance:
  18. instance-id: springcloud-config-server1
  19. appname: ${spring.application.name}
  20. prefer-ip-address: true
  21. lease-renewal-interval-in-seconds: 5
  22. lease-expiration-duration-in-seconds: 5
  23. client:
  24. service-url:
  25. defaultZone: http://test1:9110/eureka/,http://test2:9120/eureka/

这里的search-paths

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/934604
推荐阅读
相关标签
  

闽ICP备14008679号