spring-cloud入門(mén)之eureka-server(服務(wù)發(fā)現(xiàn))
前言
Eureka是一個(gè)服務(wù)發(fā)現(xiàn)和注冊(cè)框架,細(xì)的來(lái)說(shuō),我們可以分為eureka-server(服務(wù)發(fā)現(xiàn))和eureka-client(服務(wù)注冊(cè))兩個(gè),本次我們對(duì)eureka-server(服務(wù)發(fā)現(xiàn))做一個(gè)項(xiàng)目搭建,作為spring-cloud的開(kāi)篇。
開(kāi)源地址:https://github.com/bigbeef
項(xiàng)目結(jié)構(gòu)

maven結(jié)構(gòu)大家應(yīng)該都清楚(不清楚的需要補(bǔ)一補(bǔ),百度關(guān)于maven的文章不計(jì)其數(shù)),下面我們來(lái)看一看這些關(guān)鍵文件的配置
代碼編寫(xiě)
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>
<!--打包可執(zhí)行的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/
到此項(xiàng)目搭建完成
啟動(dòng)項(xiàng)目
我們啟動(dòng)SpringCloudEurekaServerApplication中的main方法,訪(fǎng)問(wèn)http://127.0.0.1:8761

到此,eureka-server(服務(wù)發(fā)現(xiàn))項(xiàng)目搭建成功
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Eureka源碼解析服務(wù)離線(xiàn)狀態(tài)變更
- Eureka源碼閱讀Client啟動(dòng)入口注冊(cè)續(xù)約及定時(shí)任務(wù)
- Eureka源碼核心類(lèi)預(yù)備知識(shí)
- Eureka源碼閱讀之環(huán)境搭建及工程結(jié)構(gòu)
- SpringCloud?eureka(server)微服務(wù)集群搭建過(guò)程
- spring cloud-給Eureka Server加上安全的用戶(hù)認(rèn)證詳解
- spring cloud將spring boot服務(wù)注冊(cè)到Eureka Server上的方法
- Eureka源碼閱讀解析Server服務(wù)端啟動(dòng)流程實(shí)例
相關(guān)文章
Java完全二叉樹(shù)的創(chuàng)建與四種遍歷方法分析
這篇文章主要介紹了Java完全二叉樹(shù)的創(chuàng)建與四種遍歷方法,結(jié)合實(shí)例形式分析了完全二叉樹(shù)的概念、定義及遍歷操作相關(guān)實(shí)現(xiàn)技巧,并對(duì)比分析了滿(mǎn)二叉樹(shù)與完全二叉樹(shù)的區(qū)別,需要的朋友可以參考下2017-11-11
25行Java代碼將普通圖片轉(zhuǎn)換為字符畫(huà)圖片和文本的實(shí)現(xiàn)
這篇文章主要介紹了25行Java代碼將普通圖片轉(zhuǎn)換為字符畫(huà)圖片和文本的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
Java跳出當(dāng)前的多重嵌套循環(huán)的五種方法
在Java編程中,跳出多重嵌套循環(huán)可以使用break語(yǔ)句、標(biāo)號(hào)與break組合、return語(yǔ)句、標(biāo)志變量和異常處理五種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-10-10
Java中java.lang.ClassCastException異常原因以及解決方法詳解
這篇文章主要給大家介紹了關(guān)于Java中java.lang.ClassCastException異常原因以及解決方法的相關(guān)資料,ClassCastException從字面上看是類(lèi)型轉(zhuǎn)換錯(cuò)誤,通常是進(jìn)行強(qiáng)制類(lèi)型轉(zhuǎn)換時(shí)候出的錯(cuò)誤,需要的朋友可以參考下2024-02-02
在Java中實(shí)現(xiàn)線(xiàn)程安全的單例模式的常見(jiàn)方式
單例模式是一種常用的軟件設(shè)計(jì)模式,它確保一個(gè)類(lèi)只有一個(gè)實(shí)例,并提供一個(gè)全局訪(fǎng)問(wèn)點(diǎn),在多線(xiàn)程環(huán)境下,確保單例模式的線(xiàn)程安全性是非常重要的,因?yàn)槎鄠€(gè)線(xiàn)程可能會(huì)同時(shí)嘗試創(chuàng)建實(shí)例,導(dǎo)致實(shí)例不唯一的問(wèn)題,本文介紹了在Java中實(shí)現(xiàn)線(xiàn)程安全的單例模式有幾種常見(jiàn)的方式2024-09-09
SpringBoot3整合WebSocket詳細(xì)指南
SpringBoot 3 整合 WebSocket 提供了一種高效的實(shí)時(shí)通信解決方案,通過(guò)本文的配置和示例,可以快速實(shí)現(xiàn),感興趣的哦朋友跟隨小編一起看看吧2024-12-12
基于synchronized修飾靜態(tài)和非靜態(tài)方法
這篇文章主要介紹了基于synchronized修飾靜態(tài)和非靜態(tài)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
Java實(shí)現(xiàn)一個(gè)簡(jiǎn)單的定時(shí)器代碼解析
這篇文章主要介紹了Java實(shí)現(xiàn)一個(gè)簡(jiǎn)單的定時(shí)器代碼解析,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12
Java?Cookie與Session實(shí)現(xiàn)會(huì)話(huà)跟蹤詳解
session的工作原理和cookie非常類(lèi)似,在cookie中存放一個(gè)sessionID,真實(shí)的數(shù)據(jù)存放在服務(wù)器端,客戶(hù)端每次發(fā)送請(qǐng)求的時(shí)候帶上sessionID,服務(wù)端根據(jù)sessionID進(jìn)行數(shù)據(jù)的響應(yīng)2022-11-11

