本案例来自于spring官网:http://spring.io/guides/gs/service-registration-and-discovery/
JDK要求1.8或以上版本。
首先创建两个项目,eureka-service和eureka-client。
eureka-server作为eureka的服务端,提供注册服务,eureka-client作为eureka的客户端,属于一个应用,注册到eureka注册中心。
eureka-service的配置文件pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0%20http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>eureka-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version> <!--配合spring cloud版本-->
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<!--设置字符编码及java版本-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--增加eureka-server的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!--用于测试的,本例可省略-->
<dependency>
<

本案例介绍如何基于Spring Cloud Eureka实现服务注册。创建eureka-service作为服务端,提供注册服务,eureka-client作为客户端注册到服务中心。详细步骤包括项目创建、配置文件设置及启动验证。通过访问Eureka服务端和客户端,展示服务注册和发现功能。
4153

被折叠的 条评论
为什么被折叠?



