#服务搭建
1.新建一个maven项目名字自定义
2.导入相关依赖
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> <version>1.4.7.RELEASE</version> </dependency> </dependencies>
3.添加application.yml配置文件
server: #配置端口号 port: 7001 eureka: instance: hostname: localhost #配置主机名字 client: # 表示是否向 Eureka 注册中心注册自己(这个模块本身是服务器,所以不需要) register-with-eureka: false # fetch-registry如果为false,则表示自己为注册中心,客户端的化为 ture fetch-registry: false service-url: defultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #服务地址
4.在主类中添加上@EnableEurekaService注解
运行后 打开http://localhost:7001即可看到页面
注意几点:1.springboot对应的springcloud版本要一直
亲测 springboot 2.3.3RELEASE 对应springcloudHoxton.SR8
2.JDK版本建议为1.8不然会出现一系列的问题
#服务注册
1.老规矩导入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> <version>1.4.6.RELEASE</version> </dependency>
2.编写application.yml
eureka: client: service-url:#服务的地址 defaultZone: http://localhost:7001/eureka/ instance:#自己设置id instance-id: springcloud-provider-dept-8001
3.在主启动类上添加
@EnableEurekaClient