文章目录

  • 1.概述
    • 1.1.官方概述地址
    • 1.2.官方源码地址
    • 1.3.官方Eureka ServerDemo地址
    • 1.4.概述理解
      • 1.4.1.Eureka是Netflix公司开源的一个服务发现组件
      • 1.4.2.首先Eureka是一个服务注册与服务发现的中间组件:相当于Dubbo
      • 1.4.3.Eureka架构组成
        • 1.4.3.1.Eureka-Server:我们可以认为就是服务的注册中心(Register)
        • 1.4.3.2.Eureka-Client:服务提供者(Provider)和服务消费者(Consumer)
        • 1.4.3.3.架构调用流程(High level architecture 高可用架构)
          • 1.4.3.3.1.注册中心:Eureka-Server
          • 1.4.3.3.2.服务发布者:Eureka-Client(Application-Service)
          • 1.4.3.3.3.服务消费者:Eureka-Client(Application-Client)
      • 1.4.4.Eureka是是一个基于REST的服务,主要用于定位运行在应用域中的中间层服务
  • 2.Demo 应用样例
    • 2.1.Eureka Server注册中心搭建
      • 2.1.1.创建项 [demo-spring-cloud-netflix-eureka-server]
      • 2.1.2.引入Eureka Server 版本
      • 2.1.3.定义application.yml
      • 2.1.4.定义bootstrap.yml
      • 2.1.5.创建启动Java
      • 2.1.16.启动控台
    • 2.2.Eureka Server-服务发布者
      • 2.2.1.创建项目[demo-spring-cloud-netflix-eureka-provider]
      • 2.2.2.引入jar包版本
      • 2.2.3.定义application.properties
      • 2.2.4.创建启动Java
      • 2.2.5.启动验证问题:provider启动了之后立刻死掉了
      • 2.2.6.问题解决:引入spring-boot-starter-web包
      • 2.2.7.再次启动验证-启动成功-查看eureka-server注册中心
      • 2.2.8.我们在服务端provider项目中创建一个Controller
        • 2.2.8.1.HelloController
        • 2.2.8.2.页面测试:直接验证服务端服务是否正常
    • 2.3.Eureka Client-服务消费者
    • 2.4.项目源码

1.概述

1.1.官方概述地址

https://spring.io/projects/spring-cloud-netflix

1.2.官方源码地址

https://github.com/Netflix/eureka

1.3.官方Eureka ServerDemo地址

https://github.com/spring-cloud-samples/eureka

1.4.概述理解

1.4.1.Eureka是Netflix公司开源的一个服务发现组件

1.实际上Netflix开源了好多组件,Eureka只是其中的一个,大家可以查看GitHub上面的相关开源项目,

https://github.com/Netflix

1.4.2.首先Eureka是一个服务注册与服务发现的中间组件:相当于Dubbo

1.在微服务架构系统之中,我们经常提三个角色:1.1.注册中心  (Register):服务发布者将服务发布到注册中心,服务消费者从注册中心获取可以进行访问的服务列表;1.2.服务提供者(Provider):需要发布服务的应用1.3.服务消费者(Consumer):需要访问服务的应用

1.4.3.Eureka架构组成

1.4.3.1.Eureka-Server:我们可以认为就是服务的注册中心(Register)

1.4.3.2.Eureka-Client:服务提供者(Provider)和服务消费者(Consumer)

1.4.3.3.架构调用流程(High level architecture 高可用架构)

1.4.3.3.1.注册中心:Eureka-Server
1.首先,我们可以看到上面注册中心使用了集群部署:us-east-1c,us-east-1d,us-east-1e(美国东部1c,1d,1e注册中心)
2.集群中的机器,数据会进行同步复制更新(replicate),保证注册中心数据最终一致性;
1.4.3.3.2.服务发布者:Eureka-Client(Application-Service)
1.服务发布者,即下游相关的平台或者是提供服务的应用,对于自己的应用服务(Application Service),做下面的操作1.1.服务注册:将自己的服务接口方法以及服务发布的地址等,注册到Eureka Server注册中心中;1.2.服务更新:对已经发布到注册中心的服务通知进行更新操作;1.3.服务删除:通过相关操作(如停止应用操作)通知注册中心,将应用服务从注册中心删除(移除);
2.服务发布者通过Eureka这个注册中心,每30秒发送一次心跳更新注册中心的数据;如果服务消费者一段时间之内不能更新这个服务发布者的服务信息,那么90s之内,这个服务将会被注册中心移除;
1.4.3.3.3.服务消费者:Eureka-Client(Application-Client)
1.服务消费者(Application Client),在应用启动的时候,根据自己订阅的服务,会去注册中心(Eureka Server)拉取所有的服务清单列表会缓存到应用本地缓存,
2.

1.4.4.Eureka是是一个基于REST的服务,主要用于定位运行在应用域中的中间层服务

2.Demo 应用样例

2.1.Eureka Server注册中心搭建

2.1.1.创建项 [demo-spring-cloud-netflix-eureka-server]

2.1.2.引入Eureka Server 版本

这里的版本引入主要是下面这个

 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency>

当然pom里还有一些其他的内容,我们不做一一讲解
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.gaoxinfu.demo.spring.cloud</groupId><artifactId>demo-spring-cloud-netflix-eureka-server</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging><name>demo-spring-cloud-netflix-eureka-server</name><description>Eureka Server demo project</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Finchley.BUILD-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><start-class>eurekademo.EurekaApplication</start-class><java.version>1.8</java.version><docker.image.prefix>springcloud</docker.image.prefix></properties><build><plugins><plugin><groupId>com.spotify</groupId><artifactId>docker-maven-plugin</artifactId><version>0.2.3</version><configuration><baseImage>openjdk:8-jre-alpine</baseImage><imageName>${docker.image.prefix}/${project.artifactId}</imageName><exposes>8761</exposes><entryPoint>["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/${project.build.finalName}.jar"]</entryPoint><resources><resource><targetPath>/</targetPath><directory>${project.build.directory}</directory><include>${project.build.finalName}.jar</include></resource></resources></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!-- defined in spring-cloud-starter-parent pom (as documentation hint),but needs to be repeated here --><configuration><requiresUnpack><dependency><groupId>com.netflix.eureka</groupId><artifactId>eureka-core</artifactId></dependency><dependency><groupId>com.netflix.eureka</groupId><artifactId>eureka-client</artifactId></dependency></requiresUnpack></configuration></plugin><plugin><groupId>pl.project13.maven</groupId><artifactId>git-commit-id-plugin</artifactId><configuration><failOnNoGitDirectory>false</failOnNoGitDirectory></configuration></plugin><plugin><!--skip deploy (this is just a test module) --><artifactId>maven-deploy-plugin</artifactId><configuration><skip>true</skip></configuration></plugin></plugins></build><repositories><repository><id>spring-snapshots</id><name>Spring Snapshots</name><url>https://repo.spring.io/libs-snapshot</url><snapshots><enabled>true</enabled></snapshots></repository><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>spring-releases</id><name>Spring Releases</name><url>https://repo.spring.io/libs-release</url><snapshots><enabled>false</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>spring-snapshots</id><name>Spring Snapshots</name><url>https://repo.spring.io/libs-snapshot-local</url><snapshots><enabled>true</enabled></snapshots></pluginRepository><pluginRepository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone-local</url><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories></project>

2.1.3.定义application.yml

server:port: 8761eureka:client:registerWithEureka: truefetchRegistry: trueserver:waitTimeInMsWhenSyncEmpty: 0
server.port:定义Eureka Server 端口
eureka.client.registerWithEureka :表示是否将自己注册到Eureka Server,默认为true。由于当前这个应用就是Eureka Server,故而设为false。
eureka.client.fetchRegistry :表示是否从Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false。

2.1.4.定义bootstrap.yml

spring:application:name: demo-spring-cloud-netflix-eureka-servercloud:config:uri: ${CONFIG_SERVER_URL:http://localhost:8888}

2.1.5.创建启动Java

package com.gaoxinfu.demo.spring.cloud.netflix.eureka.server;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;/*** @Description:* @Author: gaoxinfu* @Date: 2020-09-11 11:18*/
@EnableAutoConfiguration
@EnableEurekaServer
public class DemoSpringCloudNetflixEurekaServerApp {public static void main(String[] args) {SpringApplication.run(DemoSpringCloudNetflixEurekaServerApp.class,args);}
}

2.1.16.启动控台

http://127.0.0.1:8761/

2.2.Eureka Server-服务发布者

2.2.1.创建项目[demo-spring-cloud-netflix-eureka-provider]

2.2.2.引入jar包版本

     <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency>

2.2.3.定义application.properties

spring.application.name=demo-srping-cloud-netflix-eureka-provider
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
server.port=8762

2.2.4.创建启动Java

package com.gaoxinfu.demo.spring.cloud.netflix.eureka.provider;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;/*** @Description:* @Author: gaoxinfu* @Date: 2020-09-13 12:04*/
@SpringBootApplication
@EnableEurekaClient
public class DemoSpringCloudNetflixEurekaProviderApp {public static void main(String[] args) {SpringApplication.run(DemoSpringCloudNetflixEurekaProviderApp.class,args);}
}

2.2.5.启动验证问题:provider启动了之后立刻死掉了

2020-09-22 14:01:12.352  INFO 19151 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3d74bf60: startup date [Tue Sep 22 14:01:12 CST 2020]; root of context hierarchy
2020-09-22 14:01:12.702  INFO 19151 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2020-09-22 14:01:12.782  INFO 19151 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e525a3bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying).   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::        (v2.0.2.RELEASE)2020-09-22 14:01:13.319  INFO 19151 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-09-22 14:01:13.478  INFO 19151 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-09-22 14:01:13.479  WARN 19151 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/demo-srping-cloud-netflix-eureka-provider/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2020-09-22 14:01:13.482  INFO 19151 --- [           main] .DemoSpringCloudNetflixEurekaProviderApp : No active profile set, falling back to default profiles: default
2020-09-22 14:01:13.496  INFO 19151 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@791d1f8b: startup date [Tue Sep 22 14:01:13 CST 2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3d74bf60
2020-09-22 14:01:14.060  INFO 19151 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=692091bb-c487-3110-9c25-53bfc11f7aa0
2020-09-22 14:01:14.077  INFO 19151 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2020-09-22 14:01:14.126  INFO 19151 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e525a3bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-09-22 14:01:14.154  WARN 19151 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2020-09-22 14:01:14.154  INFO 19151 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-09-22 14:01:14.157  WARN 19151 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2020-09-22 14:01:14.157  INFO 19151 --- [           main] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-09-22 14:01:14.557  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2020-09-22 14:01:14.564  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
2020-09-22 14:01:14.564  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'environmentManager' has been autodetected for JMX exposure
2020-09-22 14:01:14.565  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshScope' has been autodetected for JMX exposure
2020-09-22 14:01:14.567  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
2020-09-22 14:01:14.575  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
2020-09-22 14:01:14.581  INFO 19151 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,context=791d1f8b,type=ConfigurationPropertiesRebinder]
2020-09-22 14:01:14.587  INFO 19151 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2020-09-22 14:01:14.596  INFO 19151 --- [           main] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING
2020-09-22 14:01:14.620  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Initializing Eureka in region us-east-1
2020-09-22 14:01:14.764  INFO 19151 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson
2020-09-22 14:01:14.764  INFO 19151 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson
2020-09-22 14:01:14.872  INFO 19151 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml
2020-09-22 14:01:14.872  INFO 19151 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml
2020-09-22 14:01:14.990  INFO 19151 --- [           main] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Application is null : false
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2020-09-22 14:01:15.004  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2020-09-22 14:01:15.103  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : The response status is 200
2020-09-22 14:01:15.106  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 30
2020-09-22 14:01:15.107  INFO 19151 --- [           main] c.n.discovery.InstanceInfoReplicator     : InstanceInfoReplicator onDemand update allowed rate per min is 4
2020-09-22 14:01:15.110  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1600754475109 with initial instances count: 1
2020-09-22 14:01:15.113  INFO 19151 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER with eureka with status UP
2020-09-22 14:01:15.113  INFO 19151 --- [           main] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1600754475113, current=UP, previous=STARTING]
2020-09-22 14:01:15.129  INFO 19151 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER/10.56.39.27:demo-srping-cloud-netflix-eureka-provider:8762: registering service...
2020-09-22 14:01:15.142  INFO 19151 --- [           main] .DemoSpringCloudNetflixEurekaProviderApp : Started DemoSpringCloudNetflixEurekaProviderApp in 3.389 seconds (JVM running for 4.149)
2020-09-22 14:01:15.144  INFO 19151 --- [      Thread-11] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@791d1f8b: startup date [Tue Sep 22 14:01:13 CST 2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3d74bf60
2020-09-22 14:01:15.144  INFO 19151 --- [      Thread-11] o.s.c.n.e.s.EurekaServiceRegistry        : Unregistering application DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER with eureka with status DOWN
2020-09-22 14:01:15.145  WARN 19151 --- [      Thread-11] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1600754475145, current=DOWN, previous=UP]
2020-09-22 14:01:15.146  INFO 19151 --- [      Thread-11] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2020-09-22 14:01:15.147  INFO 19151 --- [      Thread-11] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2020-09-22 14:01:15.147  INFO 19151 --- [      Thread-11] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans
2020-09-22 14:01:15.148  INFO 19151 --- [      Thread-11] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2020-09-22 14:01:15.156  INFO 19151 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER/10.56.39.27:demo-srping-cloud-netflix-eureka-provider:8762 - registration status: 204
2020-09-22 14:01:15.157  INFO 19151 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER/10.56.39.27:demo-srping-cloud-netflix-eureka-provider:8762: registering service...
2020-09-22 14:01:15.162  INFO 19151 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER/10.56.39.27:demo-srping-cloud-netflix-eureka-provider:8762 - registration status: 204
2020-09-22 14:01:15.163  INFO 19151 --- [      Thread-11] com.netflix.discovery.DiscoveryClient    : Unregistering ...
2020-09-22 14:01:15.169  INFO 19151 --- [      Thread-11] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_DEMO-SRPING-CLOUD-NETFLIX-EUREKA-PROVIDER/10.56.39.27:demo-srping-cloud-netflix-eureka-provider:8762 - deregister  status: 200
2020-09-22 14:01:15.176  INFO 19151 --- [      Thread-11] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClientProcess finished with exit code 0

2.2.6.问题解决:引入spring-boot-starter-web包

      <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>

2.2.7.再次启动验证-启动成功-查看eureka-server注册中心

2.2.8.我们在服务端provider项目中创建一个Controller

2.2.8.1.HelloController

package com.gaoxinfu.demo.spring.cloud.netflix.eureka.provider.controller;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;/*** @Description:* @Author: gaoxinfu* @Date: 2020-09-22 11:41*/
@EnableEurekaClient
@RestController
public class HelloController {@ResponseBody@RequestMapping("/hello")public String hello(String name) {return name + ", Welcome to Eureka Client Test Demo!";}
}

2.2.8.2.页面测试:直接验证服务端服务是否正常

http://localhost:8762/hello?name=gaoxinfu

从上面可以看出来,服务端的服务是没有问题的;

2.3.Eureka Client-服务消费者

2.4.项目源码

https://gitee.com/gaoxinfu_admin/demo-spring-cloud/tree/master/demo-spring-cloud-netflix-eureka-server

Spring-Cloud之Spring Cloud Netflix Eureka服务注册与发现相关推荐

  1. Spring Boot(2.1.2.RELEASE) + Spring Cloud (Finchley.RELEASE)搭建服务注册和发现组件Eureka

    前言:由于版本原因,部分关于Spring Cloud的书中使用的是Spring Boot 1.x 版本,很多配置或名称在新版本中已经发生了改变.此篇文章记录的是使用较新的Spring Boot 2.x ...

  2. 【夯实Spring Cloud】Spring Cloud中的Eureka服务注册与发现详解

    本文属于[夯实Spring Cloud]系列文章,该系列旨在用通俗易懂的语言,带大家了解和学习Spring Cloud技术,希望能给读者带来一些干货.系列目录如下: [夯实Spring Cloud]D ...

  3. 详解Eureka服务注册与发现和Ribbon负载均衡【纯理论实战】

    Eureka服务注册与发现 Eureka简介 在介绍Eureka前,先说一下CAP原则 CAP原则又称CAP定理,指的是在一个分布式系统中,Consistency(一致性). Availability ...

  4. 二、Eureka服务注册与发现

    SpringCloud系列目录: 一.SpringCloud简介 二.Eureka服务注册与发现 三.Eureka注册与发现之Eureka Comsumer 四.Eureka.Server Provi ...

  5. 跟着狂神学SpringCloud(Rest环境搭建+Eureka服务注册与发现+ribbon+Feign负载均衡+Hystrix+服务熔断+Zuul路由网关+SpringCloud config分布)

    跟着狂神学SpringCloud SpringCloud 回顾之前的知识- JavaSE 数据库 前端 Servlet Http Mybatis Spring SpringMVC SpringBoot ...

  6. springcloud Eureka服务注册和发现

    一,Eureka基本介绍: Spring Cloud 封装了 Netflix 公司开发的 Eureka 模块来实现服务注册和发现(请对比Zookeeper). Eureka 采用了 C-S 的设计架构 ...

  7. Eureka服务注册与发现:什么是服务注册与发现,Server注册中心

    Eureka服务注册与发现 一套微服务架构的系统由很多单一职责的服务单元组成,而每个服务单元又有众多运行实例.例如,世界上最大的收费视频网站Netflix的系统是由600多个服务单元构成的,运行实例的 ...

  8. SpringCloud[01]Eureka服务注册与发现

    文章目录 Eureka服务注册与发现 1. Eureka基础知识 1. 什么是服务治理 2. 什么是服务注册与发现 3. Eureka包含两个组件:**Eureka Server** 和 **Eure ...

  9. Spring Cloud入门 -- Eureka服务注册与发现(Hoxton.SR5版)

    什么是Spring Cloud Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.智能路由.消息总 ...

  10. eureka 客户端服务启动了又失败了_Spring cloud Eureka服务注册与发现详解

    一.Eureka概述 (1)Eureka是什么 Eureka是一个用于服务注册与发现的框架,本身是一个基于Rest的服务. (2)Eureka的组件有哪些? Eureka的组件可分为Eureka Se ...

最新文章

  1. mybatis学习7 实战项目
  2. Memory and Trident
  3. android弹窗自动消失,Android点击popupwindow以外区域 popupwindow自动消失(转载)
  4. oracle参数文件、控制文件、数据文件、日志文件的位置及查询方法
  5. 姑娘,你为什么要编程?
  6. 重学java基础第二十三课:java基础 注释
  7. jquery插件课程1 幻灯片、城市选择、日期时间选择、拖放、方向拖动插件
  8. java中日历类:Calendar
  9. VMware客户端vSphereClient新建虚拟机
  10. 关于Mytatis动态拼接in语句并且按照指定顺序排序的问题
  11. Java中的基本数据类型和包装类型
  12. 细说文件读写操作(读写锁)
  13. YOLOv2论文理解
  14. php爬虫框架crawler
  15. opnet之Aloha
  16. PHP与MySQL交互实现网页登录注册功能(步骤超详细!!!)
  17. Ubuntu 安装 Intel 显卡驱动
  18. signature=9aadee6a3f882c84134bf5f6f04d2c93,Fw: Updated Scor Input Requirements
  19. 骗的就是你!揭露买本10大愚蠢表现
  20. “新基建”将改变什么

热门文章

  1. CS5211,CS5212,CS5256,CS5811,CS5288资料
  2. unexpected inconstancy
  3. html 仿微信语音输入,AudioRecord仿微信录制语音
  4. 多次请求后tomcat网页假死
  5. Java应届生为什么找工作那么难
  6. 如何打开mysql数据库?
  7. 通过PS修出自然的大长腿
  8. H5页面在某些手机自带浏览器后退不刷新的问题
  9. C语言自定义函数使用
  10. 不同网段共享文件服务器,不同网段ip 如何设置局域网共享?