Spring基础:快速入门spring cloud(2):服务发现之eureka
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.****.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
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的组织相关的服务 |
Discovery Service
本文将会用最简单的方式来介绍如何使用Eureka进行服务发现的,以及Spring Cloud中使用Eureka是如何方便。
Sprint Boot项目
创建一个Spring Boot项目,详细不再介绍, 集体方法可以参看如下文档。
项目 | 详细 |
---|---|
SPRING INITIALIZR | http://blog.****.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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
注解
加入注解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;@[email protected] class DiscoveryserviceApplication { public static void main(String[] args) { SpringApplication.run(DiscoveryserviceApplication.class, args); }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
设定文件
使用bootstrap和application两个设定文件来进行相关设定,入门时为了更加快速,使用最少的设定文件和设定语句,基本上只有不可或缺的才会加上,入门之后详细内容参看spring cloud官方文档即可。application.properties文件的最少作如下设定即可。
server.port=8801eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
- 1
- 2
- 3
- 4
项目 | 详细 |
---|---|
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.spring[email protected]c86b9e3: startup date [Wed Dec 28 07:59:33 CST 2016]; root of context hierarchy2016-12-28 07:59:33.434 INFO 5228 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring2016-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: default2016-12-28 07:59:33.902 INFO 5228 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.spring[email protected]c86b9e32016-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-2435c6a59fa32016-12-28 07:59:35.030 INFO 5228 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring2016-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 Tomcat2016-12-28 07:59:35.578 INFO 5228 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.62016-12-28 07:59:35.687 INFO 5228 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext2016-12-28 07:59:35.687 INFO 5228 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1785 ms2016-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 LegacyJacksonJson2016-12-28 07:59:36.404 INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson2016-12-28 07:59:36.514 INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml2016-12-28 07:59:36.514 INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml2016-12-28 07:59:37.230 INFO 5228 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING2016-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: 02016-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 LegacyJacksonJson2016-12-28 07:59:37.682 INFO 5228 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson2016-12-28 07:59:37.682 INFO 5228 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml2016-12-28 07:59:37.682 INFO 5228 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml2016-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 : Initialized2016-12-28 07:59:38.103 INFO 5228 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.spring[email protected]c86b9e32016-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.ServletException2016-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[email protected]35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.spring[email protected]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 configuration2016-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 startup2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'restartEndpoint' has been autodetected for JMX exposure2016-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 02016-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 UP2016-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 default2016-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 test2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 12016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP2016-12-28 07:59:39.400 INFO 5228 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server2016-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 88012016-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)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
Eureka Server
使用8081port就可以访问到Eureka Server的Dashboard了,从这里可以清楚地看到[Instances currently registered with Eureka]下还没有任何服务注册到这里。
home
lastn
总结
这篇文章中我们了解到了如何简单的通过1行注解和3行设定即可启动服务发现功能的Eureka的Server端,在接下来的文章中,你将会看到Client端如何注册到Eureka的Server以及其他各种组件的使用方法。
给我老师的人工智能教程打call!http://blog.****.net/jiangjunshow
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的组织相关的服务 |
Discovery Service
本文将会用最简单的方式来介绍如何使用Eureka进行服务发现的,以及Spring Cloud中使用Eureka是如何方便。
Sprint Boot项目
创建一个Spring Boot项目,详细不再介绍, 集体方法可以参看如下文档。
项目 | 详细 |
---|---|
SPRING INITIALIZR | http://blog.****.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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
注解
加入注解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;@[email protected] class DiscoveryserviceApplication { public static void main(String[] args) { SpringApplication.run(DiscoveryserviceApplication.class, args); }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
设定文件
使用bootstrap和application两个设定文件来进行相关设定,入门时为了更加快速,使用最少的设定文件和设定语句,基本上只有不可或缺的才会加上,入门之后详细内容参看spring cloud官方文档即可。application.properties文件的最少作如下设定即可。
server.port=8801eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
- 1
- 2
- 3
- 4
项目 | 详细 |
---|---|
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.spring[email protected]c86b9e3: startup date [Wed Dec 28 07:59:33 CST 2016]; root of context hierarchy2016-12-28 07:59:33.434 INFO 5228 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring2016-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: default2016-12-28 07:59:33.902 INFO 5228 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot[email protected]35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.spring[email protected]c86b9e32016-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-2435c6a59fa32016-12-28 07:59:35.030 INFO 5228 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring2016-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 Tomcat2016-12-28 07:59:35.578 INFO 5228 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.62016-12-28 07:59:35.687 INFO 5228 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext2016-12-28 07:59:35.687 INFO 5228 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1785 ms2016-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 LegacyJacksonJson2016-12-28 07:59:36.404 INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson2016-12-28 07:59:36.514 INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml2016-12-28 07:59:36.514 INFO 5228 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml2016-12-28 07:59:37.230 INFO 5228 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING2016-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: 02016-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 LegacyJacksonJson2016-12-28 07:59:37.682 INFO 5228 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson2016-12-28 07:59:37.682 INFO 5228 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml2016-12-28 07:59:37.682 INFO 5228 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml2016-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 : Initialized2016-12-28 07:59:38.103 INFO 5228 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.spring[email protected]c86b9e32016-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.ServletException2016-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[email protected]35229f85: startup date [Wed Dec 28 07:59:33 CST 2016]; parent: org.spring[email protected]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 configuration2016-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 startup2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure2016-12-28 07:59:39.164 INFO 5228 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'restartEndpoint' has been autodetected for JMX exposure2016-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 02016-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 UP2016-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 default2016-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 test2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node2016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 12016-12-28 07:59:39.384 INFO 5228 --- [ Thread-10] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP2016-12-28 07:59:39.400 INFO 5228 --- [ Thread-10] e.s.EurekaServerInitializerConfiguration : Started Eureka Server2016-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 88012016-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)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
Eureka Server
使用8081port就可以访问到Eureka Server的Dashboard了,从这里可以清楚地看到[Instances currently registered with Eureka]下还没有任何服务注册到这里。
home
lastn
总结
这篇文章中我们了解到了如何简单的通过1行注解和3行设定即可启动服务发现功能的Eureka的Server端,在接下来的文章中,你将会看到Client端如何注册到Eureka的Server以及其他各种组件的使用方法。