springcloud(01)启动Eureka Server,并将其他模块作为Eureka Client启动

1、进入https://start.spring.io/,创建一个Eureka Server 的springboot项目。

2、在idea打开项目,删掉src目录,为项目new 一个子 module,将子模块命名为eureka 。再把父模块中的pom文件中Eureka Server的包剪切到子模块中。

3、在eureka子项目中添加启动类,在启动类中添加@EnableEurekaServer注解。添加application.yml配置文件,在application.yml中加入以下配置: 

spring:
application:
name: eureka
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false

4、启动子项目,打开localhost:8761,显示eureka界面,则完成Eureka Server的启动。
5、新建一个子模块system,作为eureka client启动。
6、将子模块system新建完成后,在其application.yml配置以下内容:
spring:
application:
name: system
server:
port: 9001
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/

7、再system模块的pom文件中添加:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
8、启动system模块,打开localhost:8761,出现以下内容,则启动成功

 

 




posted @ 2020-06-30 18:52  非洲刘  阅读(423)  评论(0编辑  收藏  举报