springboot微服務 java b2b2c電子商務系統(一)服務的注冊與發現(Eureka)

一、spring cloud簡介

spring cloud 為開發人員提供了快速構建分布式系統的一些工具,包括配置管理、服務發現、斷路器、路由、微代理、事件總線、全局鎖、決策競選、分布式會話等等。它運行環境簡單,可以在開發人員的電腦上跑。Spring Cloud大型企業分布式微服務云構建的B2B2C電子商務平臺源碼請加企鵝求求:一零三八七七四六二六 .另外說明spring cloud是基于springboot的,所以需要開發中對springboot有一定的了解,如果不了解的話可以看這篇文章:2小時學會springboot。另外對于“微服務架構” 不了解的話,可以通過搜索引擎搜索“微服務架構”了解下。

二、創建一個服務提供者 (eureka client)

當client向server注冊時,它會提供一些元數據,例如主機和端口,URL,主頁等。Eureka server 從每個client實例接收心跳消息。 如果心跳超時,則通常將該實例從注冊server中刪除。

創建過程同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><groupId>com.forezp</groupId><artifactId>service-hi</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>service-hi</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Dalston.RC1</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories>
</project>通過注解@EnableEurekaClient 表明自己是一個eurekaclient.@SpringBootApplication
@EnableEurekaClient
@RestController
public class ServiceHiApplication {public static void main(String[] args) {SpringApplication.run(ServiceHiApplication.class, args);}@Value("${server.port}")String port;@RequestMapping("/hi")public String home(@RequestParam String name) {return "hi "+name+",i am from port:" +port;}
}復制代碼

僅僅@EnableEurekaClient是不夠的,還需要在配置文件中注明自己的服務注冊中心的地址,application.yml配置文件如下:

eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/
server:port: 8762
spring:application:name: service-hi復制代碼

需要指明spring.application.name,這個很重要,這在以后的服務與服務之間相互調用一般都是根據這個name 。
啟動工程,打開http://localhost:8761 ,即eureka server 的網址:

你會發現一個服務已經注冊在服務中了,服務名為SERVICE-HI ,端口為7862

這時打開 http://localhost:8762/hi?name=forezp ,你會在瀏覽器上看到 :

架構代碼如下:



來源: java B2B2C 源碼 Springcloud多租戶電子商城系統?

Spring Cloud大型企業分布式微服務云構建的B2B2C電子商務平臺源碼請加企鵝求求:一零三八七七四六二六


轉載于:https://juejin.im/post/5c3d7848e51d452ec6218838

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388482.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388482.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388482.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

linux部署服務器常用命令

fdisk -l 查分區硬盤 df -h 查空間硬盤 cd / 進目錄 ls/ll 文件列表 vi tt.txt iinsert 插入 shift: 進命令行 wq 保存%退出 cat tt.txt 內容查看 pwd 當期目錄信息 mkdir tt建目錄 cp tt.txt tt/11.txt 拷貝文件到tt下 mv 11.txt /usr/ 移動 rm -rf tt.txt 刪除不提示 rm t…

HTML和CSS面試問題總結,html和css面試總結

html和cssw3c 規范結構化標準語言樣式標準語言行為標準語言1) 盒模型常見的盒模型有w3c盒模型(又名標準盒模型)box-sizing:content-box和IE盒模型(又名怪異盒模型)box-sizing:border-box。標準盒子模型&#xff1a;寬度內容的寬度(content) border padding margin低版本IE盒子…

css清除浮動float的七種常用方法總結和兼容性處理

在清除浮動前我們要了解兩個重要的定義&#xff1a; 浮動的定義&#xff1a;使元素脫離文檔流&#xff0c;按照指定方向發生移動&#xff0c;遇到父級邊界或者相鄰的浮動元素停了下來。 高度塌陷&#xff1a;浮動元素父元素高度自適應&#xff08;父元素不寫高度時&#xff0c;…

數據遷移測試_自動化數據遷移測試

數據遷移測試Data migrations are notoriously difficult to test. They take a long time to run on large datasets. They often involve heavy, inflexible database engines. And they’re only meant to run once, so people think it’s throw-away code, and therefore …

使用while和FOR循環分布打印字符串S='asdfer' 中的每一個元素

方法1&#xff1a; s asdfer for i in s :print(i)方法2:index 0 while 1:print(s[index])index1if index len(s):break 轉載于:https://www.cnblogs.com/yuhoucaihong/p/10275800.html

山師計算機專業研究生怎么樣,山東師范大學有計算機專業碩士嗎?

山東師范大學位于山東省濟南市&#xff0c;學校是一所綜合性高等師范院校。該院校深受廣大報考專業碩士學員的歡迎&#xff0c;因此很多學員想要知道山東師范大學有沒有計算機專業碩士&#xff1f;山東師范大學是有計算機專業碩士的。下面就和大家介紹一下培養目標有哪些&#…

ZOJ-Crashing Balloon

先從最大的數開始, 深度優先遍歷. 如果是 m 和 n 的公因子, 先遍歷m的, 回溯返回的數值還是公因子, 再遍歷n. 如果有某一或幾條路徑可以讓 m 和 n 變成 1 ,說明 m 和 n 不沖突, m 勝利. 如果沒有找到一條路徑當 n 分解完成時, m 也分解完成, 則判定 m說謊(無論 n 是否說謊), n…

使用TensorFlow概率預測航空乘客人數

TensorFlow Probability uses structural time series models to conduct time series forecasting. In particular, this library allows for a “scenario analysis” form of modelling — whereby various forecasts regarding the future are made.TensorFlow概率使用結構…

python畫激活函數圖像

導入必要的庫 import math import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParams[axes.unicode_minus] False 繪制softmax函數圖像 fig plt.figure(figsize(6,4)) ax fig.add_subplot(111) x np.linspace(-10,10) y sigmoid(x)ax.s…

計算機網絡管理SIMP,計算機網絡管理實驗報告.docx

計算機網絡管理實驗報告計算機網絡管理實驗報告PAGEPAGE #計算機網絡管理實驗報告作 者&#xff1a; 孫玉虎 學 號&#xff1a;914106840229學院(系)&#xff1a;計算機科學與工程學院專 業&#xff1a;網絡工程題 目&#xff1a;SNMR報文禾口 MIB指導教師陸一飛2016年12月目錄…

tomcat集群

1】 下載安裝 httpd-2.2.15-win32-x86-no_ssl.msi 網頁服務器 32-bit Windows zip tomcat mod_jk-1.2.30-httpd-2.2.3.so Apache/IIS 用來連接后臺Tomcat的模塊&#xff0c;支持集群和負載均衡 JK 分為兩個版本 1,x 和 2.x &…

pdf.js插件使用記錄,在線打開pdf

pdf.js插件使用記錄&#xff0c;在線打開pdf 原文:pdf.js插件使用記錄&#xff0c;在線打開pdf天記錄一個js庫&#xff1a;pdf.js。主要是實現在線打開pdf功能。因為項目需求需要能在線查看pdf文檔&#xff0c;所以就研究了一下這個控件。 有些人很好奇&#xff0c;在線打開pdf…

程序員 sql面試_非程序員SQL使用指南

程序員 sql面試Today, the word of the moment is DATA, this little combination of 4 letters is transforming how all companies and their employees work, but most people don’t really know how data behaves or how to access it and they also think that this is j…

Apache+Tomcat集群負載均衡的兩種session處理方式

session共享有兩種方式&#xff1a; 1、session共享&#xff0c;多個服務器session拷貝保存&#xff0c;一臺宕機不會影響用戶的登錄狀態&#xff1b; 2、請求精確集中定位&#xff0c;即當前用戶的請求都集中定位到一臺服務器中&#xff0c;這樣單臺服務器保存了用戶的sessi…

SmartSVN:File has inconsistent newlines

用SmartSVN提交文件的時候&#xff0c;提示svn: File has inconsistent newlines 這是由于要提交的文件編碼時混合了windows和unix符號導致的。 解決方案 SmartSVN設置做如下修改可以解決問題&#xff1a; Project–>Setting選擇Working copy下的EOL-style將Default EOL-sty…

我要認真學Git了 - Config

有一天&#xff0c;當我像往常一樣打開SourceTree提交代碼&#xff0c;然后推送的時候&#xff0c;我突然意識到我只是根據肌肉記憶完成這個過程&#xff0c;我壓根不知道這其中到底發生了什么。這是個很嚴重的問題&#xff0c;作為一個技術人員&#xff0c;居然只滿足于使用工…

計算機科學與技術科研論文,計算機科學與技術學院2007年度科研論文一覽表

1Qiang Sun,Xianwen Zeng, Raihan Ur Rasool, Zongwu Ke, Niansheng Chen. The Capacity of Wireless Ad Hoc Networks with Power Control. IWCLD 2007. (EI收錄: 083511480101)2Hong jia ping. The Application of the AES in the Bootloader of AVR Microcontroller. In: DC…

r a/b 測試_R中的A / B測試

r a/b 測試什么是A / B測試&#xff1f; (What is A/B Testing?) A/B testing is a method used to test whether the response rate is different for two variants of the same feature. For instance, you may want to test whether a specific change to your website lik…

一臺機器同時運行兩個Tomcat

如果不加任何修改&#xff0c;在一臺服務器上同時運行兩個Tomcat服務顯然會發生端口沖突。假設現在已經按照正常的方式安裝配置好了第一個Tomcat,第二個如何設置呢&#xff1f;以下是使用Tomcat5.5解壓版本所做的實驗。 解決辦法&#xff1a; 1.解壓Tomcat到一個新的目錄&#…

PHP獲取IP地址的方法,防止偽造IP地址注入攻擊

PHP獲取IP地址的方法,防止偽造IP地址注入攻擊 原文:PHP獲取IP地址的方法,防止偽造IP地址注入攻擊PHP獲取IP地址的方法 /*** 獲取客戶端IP地址* <br />來源&#xff1a;ThinkPHP* <br />"X-FORWARDED-FOR" 是代理服務器通過 HTTP Headers 提供的客戶端IP。…