赞
踩
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-eureka-server</artifactId>-->
<!-- <version>1.4.7.RELEASE</version>-->
<!-- </dependency>-->
server:
port: 7001
eureka:
instance:
hostname: localhost #eureka服务端的实例名称
client:
fetch-registry: false # false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
register-with-eureka: false # 是否将自己注册到Eureka服务器中,本身是服务器,无需注册
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# 设置与Eureka Server交互的地址查询服务和注册服务都需要依赖这个defaultZone地址
@SpringBootApplication
@EnableEurekaServer
public class Eureka_7001 {
public static void main(String[] args) {
SpringApplication.run(Eureka_7001.class,args);
}
}
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/
# 将服务注册到 Eureka 服务中心 7001
@SpringBootApplication
@EnableEurekaClient
public class DeptProvider_8001 {
public static void main(String[] args) {
SpringApplication.run(DeptProvider_8001.class,args);
}
}
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/ # 将服务注册到 Eureka 服务中心 7001
instance:
instance-id: springcloud-8001
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka/ # 将服务注册到 Eureka 服务中心 7001
instance:
instance-id: springcloud-8001
prefer-ip-address: true # true访问路径可以显示IP地址
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
info:
app.name: qk-springcloud
company.name: www.qk.com
@Autowired private DiscoveryClient client; @GetMapping("/discovery") public Object discovery(){ //获得微服务列表清单 List<String> list = client.getServices(); System.out.println("client.getServices()==>"+list); //得到一个具体的微服务! List<ServiceInstance> serviceInstanceList = client.getInstances("SPRINGCLOUD-PROVIDER-DEPT"); for (ServiceInstance serviceInstance : serviceInstanceList) { System.out.println( serviceInstance.getServiceId()+"\t"+ serviceInstance.getHost()+"\t"+ serviceInstance.getPort()+"\t"+ serviceInstance.getUri() ); } return this.client; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。