1. 新建sping boot eureka server

新建立spring starter  project

修改pom.xml文件

在parent后追加

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

追加

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>

应用

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication
@EnableEurekaServer
public class SpringBootEurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(SpringBootEurekaServerApplication.class, args);
}
}

属性文件

server.port=8761

spring.application.name=Spring-Boot-Admin-Web
eureka.instance.hostname=localhost eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

2. 建立spring boot eureka client

pom.xml

   	<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>

应用

package com.example;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @SpringBootApplication
@RestController
@EnableEurekaClient
public class SpringBootEurekaClientApplication { @Autowired
private DiscoveryClient discoveryClient; @RequestMapping("/")
String home() {
return "Hello World!";
} @RequestMapping("/registered")
public String getRegistered(){
List<ServiceInstance> list = discoveryClient.getInstances("STORES");
System.out.println(discoveryClient.getLocalServiceInstance());
System.out.println("discoveryClient.getServices().size() = " + discoveryClient.getServices().size()); for( String s : discoveryClient.getServices()){
System.out.println("services " + s);
List<ServiceInstance> serviceInstances = discoveryClient.getInstances(s);
for(ServiceInstance si : serviceInstances){
System.out.println(" services:" + s + ":getHost()=" + si.getHost());
System.out.println(" services:" + s + ":getPort()=" + si.getPort());
System.out.println(" services:" + s + ":getServiceId()=" + si.getServiceId());
System.out.println(" services:" + s + ":getUri()=" + si.getUri());
System.out.println(" services:" + s + ":getMetadata()=" + si.getMetadata());
} } System.out.println(list.size());
if (list != null && list.size() > 0 ) {
System.out.println( list.get(0).getUri() );
}
return null;
} public static void main(String[] args) {
SpringApplication.run(SpringBootEurekaClientApplication.class, args);
}
}

配置文件

spring.application.name=cloud-simple-service
server.port=8011 eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

最新文章

  1. 玩转spring boot——结合jQuery和AngularJs
  2. js加密的密文让PHP解密(AES算法)
  3. [Solution] Microsoft Windows 服务(1) C#创建Windows服务
  4. 04-树6 Complete Binary Search Tree
  5. Windows下搭建MySql Master-Master Replication
  6. 桂电在线-php-提取菜单到配置文件2
  7. 关于unsigned int和int的加法
  8. cf C. Matrix
  9. memcached介绍及基本使用
  10. spark install
  11. ubuntu系统安装FTP
  12. /home 和 /root
  13. js实现搜索记录列表
  14. vue中的$route和$router的区别
  15. Python协程(真才实学,想学的进来)
  16. 【嵌入式】Arduino编程基础到应用全解析
  17. 设计模式之备忘录模式(Memento )
  18. Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)
  19. C#连接数据库open函数失败
  20. Unity调用Windows弹框、提示框(确认与否,中文)

热门文章

  1. XP 安装Oralce 10g 数据库
  2. NIO SelectionKey中定义的4种事件
  3. 自动刷新页面为了session不过期
  4. windows registry =&gt; control pannel
  5. 如何写一个HttpClient[1]——URI的处理
  6. iOS多线程同步锁
  7. gitlab多人协作开发
  8. SACS +Petrel 2009地震
  9. Linux C 学习
  10. ThreadLocal是什么?保证线程安全