Spring基础:快速入门spring cloud(2):服务发现之eureka

这里写图片描述

Spring Cloud是Spring总多的Project中的一个,它提供了一整套的工具帮助系统架构师们在进行分布式设计的时候可以拿来即用, 在创建和发布微服务时极为便捷和有效。本系列文章将会使用最简单的例子和最为容易的方式来学习Spring Cloud。本文将会介绍如何使用Spring Cloud的Eureka实现服务发现。

构成

Spring Cloud由很多子项目构成,为了介绍方便,挑出一些项目中常用的进行如下构成。

这里写图片描述

具体各个Service之间的关系不再一一展示,将其粗暴地分为框架类服务(Spring Cloud服务)也业务逻辑服务两种,各服务功能和实现简单如下说明。

项目详细
Config ServiceSpring Cloud Config:统一配置管理服务
Dashboard ServiceHystrix Dashboard
Api Route ServiceZuul:Api Gateway
Discovery ServiceEureka:服务发现
User ServiceRESTFUL的用户相关的服务
Org ServiceRESTFUL的组织相关的服务

Discovery Service

这里写图片描述

本文将会用最简单的方式来介绍如何使用Eureka进行服务发现的,以及Spring Cloud中使用Eureka是如何方便。

Sprint Boot项目

创建一个Spring Boot项目,详细不再介绍, 集体方法可以参看如下文档。

项目详细
SPRING INITIALIZRhttp://blog.csdn.net/liumiaocn/article/details/53442364

Eureka Server

Pom设定

需要将 <artifactId>spring-cloud-starter-eureka-server</artifactId>加入到POM中,可以参照如下Pom示例。

<?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.liumiaocn.demo.springcloud</groupId>
    <artifactId>discoveryservice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>discoveryservice</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.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-server</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>Camden.BUILD-SNAPSHOT</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-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

注解

加入注解EnableEurekaServer,在Spring boot的应用中只需这样一行就将EurekaServer引入其中。

package com.liumiaocn.demo.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class DiscoveryserviceApplication {

    public static void main(String[] args) {
        SpringApplication.run(DiscoveryserviceApplication.class, args);
    }
}

设定文件

使用bootstrap和application两个设定文件来进行相关设定,入门时为了更加快速,使用最少的设定文件和设定语句,基本上只有不可或缺的才会加上,入门之后详细内容参看spring cloud官方文档即可。application.properties文件的最少作如下设定即可。

server.port=8801
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
项目详细
server.portEureka Server的Dashboard所使用的port
eureka.client.register-with-eureka是否要注册到服务器端,因为此处为Eureka Server,所以设定为false
eureka.client.fetch-registry是否从服务器端取得注册信息,因为此处为Eureka Server,所以设定为false
eureka.client.serviceUrl.defaultZone设定为为http://localhost:8801/eureka/,缺省为8761端口。

启动

2016-12-28 07:59:33.200  INFO 5228 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@c86b9e3: startup date [Wed Dec 28 07:59:33 CST 2016]; root of context hierarchy
2016-12-28 07:59:33.434  INFO 5228 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-12-28 07:59:33.466  INFO 5228 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fb56a29e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2016-12-28 07:59:33.902  INFO 5228 --- [           main] c.l.d.s.DiscoveryserviceApplication      : No active profile set, falling back to default profiles: default
2016-12-28 07:59:33.902  INFO 5228 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@c86b9e3
2016-12-28 07:59:34.796  WARN 5228 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2016-12-28 07:59:34.967  INFO 5228 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=37576f2c-11e3-3d56-80ff-2435c6a59fa3
2016-12-28 07:59:35.030  INFO 5228 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-12-28 07:59:35.139  INFO 5228 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fb56a29e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-12-28 07:59:35.562  INFO 5228 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8801 (http)
2016-12-28 07:59:35.578  INFO 5228 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-12-28 07:59:35.578  INFO 5228 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2016-12-28 07:59:35.687  INFO 5228 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-12-28 07:59:35.687  INFO 5228 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1785 ms
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'metricsFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'webRequestTraceFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'servletContainer' to urls: [/eureka/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'applicationContextIdFilter' to: [/*]
2016-12-28 07:59:36.248  INFO 5228 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2016-12-28 07:59:36.342  INFO 5228 --- [ost-startStop-1] c.s.j.s.i.a.WebApplicationImpl           : Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'
2016-12-28 07:59:36.404  INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson
2016-12-28 07:59:36.404  INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson
2016-12-28 07:59:36.514  INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml
2016-12-28 07:59:36.514  INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml
2016-12-28 07:59:37.230  INFO 5228 --- [           main] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING
2016-12-28 07:59:37.292  INFO 5228 --- [           main] com.netflix.discovery.DiscoveryClient    : Client configured to neither register nor query for data.
2016-12-28 07:59:37.292  INFO 5228 --- [           main] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1482883177292 with initial instances count: 0
2016-12-28 07:59:37.370  INFO 5228 --- [           main] c.n.eureka.DefaultEurekaServerContext    : Initializing ...
2016-12-28 07:59:37.370  INFO 5228 --- [           main] c.n.eureka.cluster.PeerEurekaNodes       : Adding new peer nodes [http://localhost:8761/eureka/]
2016-12-28 07:59:37.682  INFO 5228 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson
2016-12-28 07:59:37.682  INFO 5228 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson
2016-12-28 07:59:37.682  INFO 5228 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml
2016-12-28 07:59:37.682  INFO 5228 --- [           main] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml
2016-12-28 07:59:37.791  INFO 5228 --- [           main] c.n.eureka.cluster.PeerEurekaNodes       : Replica node URL:  http://localhost:8761/eureka/
2016-12-28 07:59:37.807  INFO 5228 --- [           main] c.n.e.registry.AbstractInstanceRegistry  : Finished initializing remote region registries. All known remote regions: []
2016-12-28 07:59:37.807  INFO 5228 --- [           main] c.n.eureka.DefaultEurekaServerContext    : Initialized
2016-12-28 07:59:38.103  INFO 5228 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@c86b9e3
2016-12-28 07:59:38.228  INFO 5228 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[GET]}" onto public java.lang.String org.springframework.cloud.netflix.eureka.server.EurekaController.status(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.Object>)
2016-12-28 07:59:38.228  INFO 5228 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/lastn],methods=[GET]}" onto public java.lang.String org.springframework.cloud.netflix.eureka.server.EurekaController.lastn(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.Object>)
2016-12-28 07:59:38.228  INFO 5228 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-12-28 07:59:38.228  INFO 5228 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-12-28 07:59:38.259  INFO 5228 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-12-28 07:59:38.259  INFO 5228 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-12-28 07:59:38.290  INFO 5228 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health || /health.json],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info || /info.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/restart || /restart.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/refresh || /refresh.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.836  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/resume || /resume.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.value(java.util.Map<java.lang.String, java.lang.String>)
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/reset],methods=[POST]}" onto public java.util.Map<java.lang.String, java.lang.Object> org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.reset()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/pause || /pause.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/archaius || /archaius.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2016-12-28 07:59:38.852  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env || /env.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.868  INFO 5228 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/features || /features.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-12-28 07:59:38.977  INFO 5228 --- [           main] o.s.ui.freemarker.SpringTemplateLoader   : SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@c86b9e3] and template loader path [classpath:/templates/]
2016-12-28 07:59:38.977  INFO 5228 --- [           main] o.s.w.s.v.f.FreeMarkerConfigurer         : ClassTemplateLoader for Spring macros added to FreeMarker configuration
2016-12-28 07:59:39.070  WARN 5228 --- [           main] o.s.c.n.a.ArchaiusAutoConfiguration      : No spring.application.name found, defaulting to 'application'
2016-12-28 07:59:39.070  WARN 5228 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2016-12-28 07:59:39.070  INFO 5228 --- [           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.
2016-12-28 07:59:39.086  WARN 5228 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2016-12-28 07:59:39.086  INFO 5228 --- [           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.
2016-12-28 07:59:39.164  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-12-28 07:59:39.164  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshScope' has been autodetected for JMX exposure
2016-12-28 07:59:39.164  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'environmentManager' has been autodetected for JMX exposure
2016-12-28 07:59:39.164  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
2016-12-28 07:59:39.164  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure
2016-12-28 07:59:39.164  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'restartEndpoint' has been autodetected for JMX exposure
2016-12-28 07:59:39.164  INFO 5228 --- [           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]
2016-12-28 07:59:39.180  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'restartEndpoint': registering with JMX server as MBean [org.springframework.cloud.context.restart:name=restartEndpoint,type=RestartEndpoint]
2016-12-28 07:59:39.195  INFO 5228 --- [           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]
2016-12-28 07:59:39.195  INFO 5228 --- [           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=35229f85,type=ConfigurationPropertiesRebinder]
2016-12-28 07:59:39.212  INFO 5228 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.endpoint:name=refreshEndpoint,type=RefreshEndpoint]
2016-12-28 07:59:39.369  INFO 5228 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] o.s.c.n.e.server.EurekaServerBootstrap   : Setting the eureka configuration..
2016-12-28 07:59:39.384  INFO 5228 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Registering application unknown with eureka with status UP
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] o.s.c.n.e.server.EurekaServerBootstrap   : Eureka data center value eureka.datacenter is not set, defaulting to default
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] o.s.c.n.e.server.EurekaServerBootstrap   : Eureka environment value eureka.environment is not set, defaulting to test
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] o.s.c.n.e.server.EurekaServerBootstrap   : isAws returned false
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] o.s.c.n.e.server.EurekaServerBootstrap   : Initialized server context
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl    : Got 1 instances from neighboring DS node
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl    : Renew threshold is: 1
2016-12-28 07:59:39.384  INFO 5228 --- [      Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl    : Changing status to UP
2016-12-28 07:59:39.400  INFO 5228 --- [      Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2016-12-28 07:59:39.462  INFO 5228 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8801 (http)
2016-12-28 07:59:39.462  INFO 5228 --- [           main] c.n.e.EurekaDiscoveryClientConfiguration : Updating port to 8801
2016-12-28 07:59:39.478  INFO 5228 --- [           main] c.l.d.s.DiscoveryserviceApplication      : Started DiscoveryserviceApplication in 7.073 seconds (JVM running for 7.555)

Eureka Server

使用8081port就可以访问到Eureka Server的Dashboard了,从这里可以清楚地看到[Instances currently registered with Eureka]下还没有任何服务注册到这里。

home

这里写图片描述

lastn

这里写图片描述

总结

这篇文章中我们了解到了如何简单的通过1行注解和3行设定即可启动服务发现功能的Eureka的Server端,在接下来的文章中,你将会看到Client端如何注册到Eureka的Server以及其他各种组件的使用方法。

  • 15
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值