1.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency>
-
server:
port: 7001
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false #false表示不向注册中心注册自己
fetch-registry: false #false表示自己就是注册中心,职责是维护实例,不参加检索
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #设置eureka server的交互地址,即对外暴露的地址
-
-
==注意:要在类前加@EnableEurekaServer注解==
-
1 package com.XXX; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 7 @SpringBootApplication 8 @EnableEurekaServer 9 public class Eureka7001_APP { 10 public static void main(String[] args) { 11 SpringApplication.run(Eureka7001_APP.class,args); 12 } 13 }
启动主程序,访问该服务地址即可
1 <dependency> 2 <groupId>org.springframework.cloud</groupId> 3 <artifactId>spring-cloud-starter-eureka</artifactId> 4 </dependency> 5 <dependency> 6 <groupId>org.springframework.cloud</groupId> 7 <artifactId>spring-cloud-starter-config</artifactId> 8 </dependency>
2.修改yml
-
-
==理解:小区用户要找到物业管理处的地址进行注册==
1 eureka: 2 client: 3 service-url: 4 defaultZone: http://localhost:7001/eureka
3.
1 @SpringBootApplication 2 @EnableEurekaClient//注表名自己是注册方,将服务注入eureka
3 public class Provider8001_APP { public static void main(String[] args) { SpringApplication.run(Provider8001_APP.class,args);
}
}主机名称与服务名称的修改
- 修改服务名称,在yml中eureka节点下添加如下内容
-
eureka: instance: instance-id: dept8001 #修改别名 prefer-ip-address: true #显示IP地址