SpringCloud系列研究---Eureka服务发现

:建立项目工程spring

新建project浏览器

这里选择gradlespringboot

 直接nextapp

 

继续nextfetch

最后点击finishgradle

二:建立Eureka服务中心spa

选择第一步中建立的项目,右键选择new--->module.net

选择Spring Initializr,而后nextcode

这里输入Group、Artifact,并选择Gradle Project,而后nextserver

 

选择Eureka Server,而后点击next

 输入module name而后finish

我这里把几个都勾上了,而后OK

三:代码

代码很简单,只须要在springboot工程的启动application类上加一个@EnableEurekaServer注解就好了,具体以下:

 1 package com.cloud.microservice.demo.eurekaserver;  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 @EnableEurekaServer  8 @SpringBootApplication  9 public class EurekaServerApplication { 10 
11     public static void main(String[] args) { 12         SpringApplication.run(EurekaServerApplication.class, args); 13  } 14 }

eureka server的配置文件appication.yml:

 1 server:  2   port: 9090
 3 
 4 eureka:  5  instance:  6  hostname: localhost  7  client:  8     registerWithEureka: false
 9     fetchRegistry: false
10  serviceUrl: 11       defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

启动工程,打开浏览器访问: http://localhost:9090,界面以下:

相关文章
相关标签/搜索