客户端从springcloud-config配置中心引用配置文件

蔚落 2022-04-15 03:22 334阅读 0赞

1.在客户端项目的resources目录下新建一个bootstrap.yml 文件 文件内容如下:

  1. eureka:
  2. client:
  3. register-with-eureka: true
  4. fetch-registry: true
  5. healthcheck:
  6. enabled: true
  7. serviceUrl:
  8. # 注册中心的地址
  9. defaultZone: http://localhost:8761/eureka/
  10. spring:
  11. application:
  12. name: didispace
  13. cloud:
  14. config:
  15. discovery:
  16. enabled: true
  17. # eureka注册中心服务端的id
  18. service-id: config-server
  19. # 具体使用那个配置文件
  20. profile: dev
  21. # git上的客户端配置文件对应的分支
  22. label: fuyongnan
  23. fail-fast: true
  24. bus:
  25. enabled: true
  26. trace:
  27. enabled: true
  28. ###rabbitmq 中间件配置
  29. rabbitmq:
  30. host: 10.125.211.24
  31. port: 5672
  32. username: admin
  33. password: kye123

客户端对应的pom文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.kyx</groupId>
  6. <artifactId>config-client</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>config-client</name>
  10. <description>Demo project for Spring Boot</description>
  11. <parent>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-parent</artifactId>
  14. <version>2.0.1.RELEASE</version>
  15. <relativePath/> <!-- lookup parent from repository -->
  16. </parent>
  17. <properties>
  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  20. <java.version>1.8</java.version>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-web</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework.cloud</groupId>
  29. <artifactId>spring-cloud-starter-config</artifactId>
  30. <version>2.0.1.RELEASE</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework.cloud</groupId>
  34. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  35. <version>2.0.2.RELEASE</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework.boot</groupId>
  39. <artifactId>spring-boot-starter-actuator</artifactId>
  40. </dependency>
  41. <dependency>
  42. <groupId>org.springframework.cloud</groupId>
  43. <artifactId>spring-cloud-starter-bus-amqp</artifactId>
  44. <version>2.0.0.RELEASE</version>
  45. </dependency>
  46. <dependency>
  47. <groupId>net.logstash.logback</groupId>
  48. <artifactId>logstash-logback-encoder</artifactId>
  49. <version>5.2</version>
  50. </dependency>
  51. <dependency>
  52. <groupId>io.springfox</groupId>
  53. <artifactId>springfox-swagger2</artifactId>
  54. <version>2.7.0</version>
  55. </dependency>
  56. <dependency>
  57. <groupId>io.springfox</groupId>
  58. <artifactId>springfox-swagger-ui</artifactId>
  59. <version>2.7.0</version>
  60. </dependency>
  61. <dependency>
  62. <groupId>org.jmock</groupId>
  63. <artifactId>jmock-junit4</artifactId>
  64. <version>2.8.4</version>
  65. <scope>test</scope>
  66. </dependency>
  67. <dependency>
  68. <groupId>org.mockito</groupId>
  69. <artifactId>mockito-all</artifactId>
  70. <version>2.0.2-beta</version>
  71. <scope>test</scope>
  72. </dependency>
  73. <dependency>
  74. <groupId>net.bytebuddy</groupId>
  75. <artifactId>byte-buddy</artifactId>
  76. <version>1.8.16</version>
  77. </dependency>
  78. <dependency>
  79. <groupId>net.bytebuddy</groupId>
  80. <artifactId>byte-buddy-agent</artifactId>
  81. <version>1.8.16</version>
  82. <scope>test</scope>
  83. </dependency>
  84. <dependency>
  85. <groupId>org.powermock</groupId>
  86. <artifactId>powermock-module-junit4</artifactId>
  87. <version>1.7.4</version>
  88. <scope>test</scope>
  89. </dependency>
  90. <!--<dependency>
  91. <groupId>org.springframework.cloud</groupId>
  92. <artifactId>spring-cloud-context</artifactId>
  93. <version>2.0.1.RELEASE</version>
  94. </dependency>
  95. <dependency>
  96. <groupId>org.springframework.cloud</groupId>
  97. <artifactId>spring-cloud-commons</artifactId>
  98. <version>2.0.1.RELEASE</version>
  99. </dependency>-->
  100. </dependencies>
  101. <build>
  102. <plugins>
  103. <plugin>
  104. <groupId>org.springframework.boot</groupId>
  105. <artifactId>spring-boot-maven-plugin</artifactId>
  106. </plugin>
  107. </plugins>
  108. </build>
  109. </project>

注意事项:
springboot 版本使2.0.1.RELEASE的版本

发表评论

表情:
评论列表 (有 0 条评论,334人围观)

还没有评论,来说两句吧...

相关阅读