您好,登錄后才能下訂單哦!
前言
Eureka是一個服務發現和注冊框架,細的來說,我們可以分為eureka-server(服務發現)和eureka-client(服務注冊)兩個,本次我們對eureka-server(服務發現)做一個項目搭建,作為spring-cloud的開篇。
開源地址:https://github.com/bigbeef
項目結構
maven結構大家應該都清楚(不清楚的需要補一補,百度關于maven的文章不計其數),下面我們來看一看這些關鍵文件的配置
代碼編寫
cppba-spring-cloud > pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cppba</groupId> <artifactId>cppba-spring-cloud</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <name>${project.artifactId}</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.5.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <spring-cloud.version>Dalston.SR2</spring-cloud.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <modules> <module>cppba-spring-cloud-eureka-server</module> </modules> </project>
cppba-spring-cloud-eureka-server > 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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>cppba-spring-cloud-eureka-server</artifactId> <packaging>jar</packaging> <name>${project.artifactId}</name> <parent> <groupId>com.cppba</groupId> <artifactId>cppba-spring-cloud</artifactId> <version>1.0.0</version> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <build> <finalName>${project.name}</finalName> <plugins> <!--打包可執行的jar--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
SpringCloudEurekaServerApplication.java
package com.cppba; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer @SpringBootApplication public class SpringCloudEurekaServerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudEurekaServerApplication.class, args); } }
application.properties
server.port=8761 eureka.instance.hostname=eureka-server eureka.client.registerWithEureka=false eureka.client.fetchRegistry=false eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
到此項目搭建完成
啟動項目
我們啟動SpringCloudEurekaServerApplication中的main方法,訪問http://127.0.0.1:8761
到此,eureka-server(服務發現)項目搭建成功
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。