



在启动类上添加注解 @EnableEurekaServer

增加配置application.yml
server:
port: 8761 #修改端口号
eureka:
instance:
hostname: eureka-server #eureka服务端起个名字
client:
由于自己就是服务器,不需要注册到自己
registerWithEureka: false
由于自己就是服务器,不需要注册到自己
fetchRegistry: false
serviceUrl:
注册中心的地址
defaultZone: http://{server.port}/eureka/

- 访问注册中心页面
http://localhost:8761/ 也可以打成jar包直接在后台运行
image.png
出现这样的网页证明启动成功,如图所示,还没有任何服务在这个服务端注册。
接下来我们尝试创建一个服务来在这个Eureka server进行注册。
1.新建一个Spring boot项目,参考上面步骤,选择这个创建

并做以下配置,注意port:和8770之间是有一个空格的,这个空格是一定不能少的。
server:
port: 8770
enable-self-preservation: false
spring:
application:
name: eureka-server
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
在当前项目 pom 文件 添加下面代码
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


网友评论