首页 > 编程语言 > 详细

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

时间:2017-09-20 18:44:10      阅读:298      评论:0      收藏:0      [点我收藏+]

:创建项目工程

新建project

技术分享

这里选择gradle

技术分享

 直接next

 技术分享

继续next

技术分享

最后点击finish

技术分享

二:创建Eureka服务中心

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

技术分享

选择Spring Initializr,然后next

技术分享

这里输入Group、Artifact,并选择Gradle Project,然后next

技术分享

 

选择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,界面如下:

技术分享

 

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

原文:http://www.cnblogs.com/chxuyuan/p/7562751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!