fresh - 云代码空间
——
<span style="font-size: 16px;"> <dependency> <groupId>org.springframework.boot</groupId> <artifactId><span style="font-size: 16px;">spring-boot-starter-actuator</span></artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId><span style="font-size: 16px;">spring-cloud-starter-bus-amqp</span></artifactId> </dependency></span>yml文件配置:
<span style="font-size: 16px;">server: port: 5012 spring: application: name: honghu-member-client profiles: active: dev,discoveryClient cloud: config: discovery: enabled: true service-id: commonservice-config-server <span style="font-size: 16px;"><strong>name: honghu-member profile: dev bus: trace: enabled: true #开启消息跟踪 </strong> <strong>rabbitmq: host: 192.168.1.254 port: 5672 username: honghu password: honghu</strong> </span> eureka: client: serviceUrl: defaultZone: http://honghu:123456@localhost:8761/eureka/ instance: prefer-ip-address: true logging: level: root: INFO org.springframework.security: INFO management: security: enabled: false security: basic: enabled: false</span>编写一个测试类(MemberController.java),用来获取配置项
<span style="font-size: 16px;">package com.honghu.cloud.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; <strong>@RefreshScope</strong> @RestController public class MemberController { @Value("${profile}") private String profile; @GetMapping("/profile") public String getProfile() { return this.profile; } }</span>3. 查看注册中心,commonservice-config、honghu-member-service服务是否已经注册成功