在之前的項目中https://blog.csdn.net/u011164906/article/details/79734908
寫個controller
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class HelloController {
@Autowired
DiscoveryClient discoveryClient;
@GetMapping("/user-instance")
public List<ServiceInstance> showInfo(){
return this.discoveryClient.getInstances("provider-user");
}
}
訪問 http://localhost:8080/user-instance
會的到如下信息
自定義數據
eureka:
instance:
metadata-map:
my-metadata: 123