Skip to content

如何获取配置

halower edited this page Mar 2, 2018 · 1 revision

一、如何获取配置信息

  1. 添加如下依赖
 <dependency>
           <groupId>org.springframework.cloud</groupId>
           <artifactId>spring-cloud-starter-config</artifactId>
       </dependency>

       <dependency>
           <groupId>org.springframework.cloud</groupId>
           <artifactId>spring-cloud-starter-bus-amqp</artifactId>
  </dependency>
  1. 创建bootstrap.yml配置,指定从配置中心获取相关的配置信息
spring:
  application:
    name: scbp.api-test-service
  cloud:
    config:
      discovery:
        enabled: true
        service-id: scbp.config-server
    bus:
        trace:
          enabled: true     # 开启cloud bus的跟踪
    rabbitmq:
      host: localhost
      port: 5672
      username: guest
      password: guest

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:xxxxx/eureka/
management:
  security:
    enabled: false
    1. 添加@RefreshScope注解
Clone this wiki locally