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.mzph.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。…