Spring Cloud是Spring总多的Project中的一个,它提供了一整套的工具帮助系统架构师们在进行分布式设计的时候可以拿来即用, 在创建和发布微服务时极为便捷和有效。本系列文章将会使用最简单的例子和最为容易的方式来学习Spring Cloud。本文将会介绍如何使用Spring Cloud的Eureka实现服务发现。
Spring Cloud由很多子项目构成,为了介绍方便,挑出一些项目中常用的进行如下构成。
具体各个Service之间的关系不再一一展示,将其粗暴地分为框架类服务(Spring Cloud服务)也业务逻辑服务两种,各服务功能和实现简单如下说明。
项目 | 详细 |
---|---|
Config Service | Spring Cloud Config:统一配置管理服务 |
Dashboard Service | Hystrix Dashboard |
Api Route Service | Zuul:Api Gateway |
Discovery Service | Eureka:服务发现 |
User Service | RESTFUL的用户相关的服务 |
Org Service | RESTFUL的组织相关的服务 |
本文将会用最简单的方式来介绍如何使用Eureka进行服务发现的,以及Spring Cloud中使用Eureka是如何方便。
创建一个Spring Boot项目,详细不再介绍, 集体方法可以参看如下文档。
项目 | 详细 |
---|---|
SPRING INITIALIZR | http://blog.csdn.net/liumiaocn/article/details/53442364 |
需要将
加入到POM中,可以参照如下Pom示例。
spring-cloud-starter-eureka-server
<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.0modelVersion>
<groupId>com.liumiaocn.demo.springcloudgroupId>
<artifactId>discoveryserviceartifactId>
<version>0.0.1-SNAPSHOTversion>
<packaging>jarpackaging>
<name>discoveryservicename>
<description>Demo project for Spring Bootdescription>
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>1.4.3.RELEASEversion>
<relativePath/>
parent>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
<java.version>1.8java.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-eureka-serverartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-dependenciesartifactId>
<version>Camden.BUILD-SNAPSHOTversion>
<type>pomtype>
<scope>importscope>
dependency>
dependencies>
dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
<repositories>
<repository>
<id>spring-snapshotsid>
<name>Spring Snapshotsname>
<url>https://repo.spring.io/snapshoturl>
<snapshots>
<enabled>trueenabled>
snapshots>
repository>
<repository>
<id>spring-milestonesid>
<name>Spring Milestonesname>
<url>https://repo.spring.io/milestoneurl>
<snapshots>
<enabled>falseenabled>
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.port | Eureka 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)
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)
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> 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)
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 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)
使用8081port就可以访问到Eureka Server的Dashboard了,从这里可以清楚地看到[Instances currently registered with Eureka]下还没有任何服务注册到这里。
这篇文章中我们了解到了如何简单的通过1行注解和3行设定即可启动服务发现功能的Eureka的Server端,在接下来的文章中,你将会看到Client端如何注册到Eureka的Server以及其他各种组件的使用方法。