Spring Cloud
是一個基於Spring Boot
實現的雲應用開發工具,它爲基於JVM的雲應用開發中涉及的配置管理、服務發現、斷路器、智能路由、微代理、控制總線、全局鎖、決策競選、分佈式會話和集羣狀態管理等操做提供了一種簡單的開發方式。html
Spring Cloud
包含了多個子項目(針對分佈式系統中涉及的多個不一樣開源產品),好比:Spring Cloud Config
、Spring Cloud Netflix
、Spring Cloud CloudFoundry
、Spring Cloud AWS
、Spring Cloud Security
、Spring Cloud Commons
、Spring Cloud Zookeeper
、Spring Cloud CLI
等項目。java
「微服務架構」在這幾年很是的火熱,以致於關於微服務架構相關的開源產品被反覆的說起(好比: netflix
、dubbo
),Spring Cloud
也因Spring
社區的強大知名度和影響力也被廣大架構師與開發者備受關注。node
那麼什麼是「微服務架構」呢?簡單的說,微服務架構就是將一個完整的應用從數據存儲開始垂直拆分紅多個不一樣的服務,每一個服務都能獨立部署、獨立維護、獨立擴展,服務與服務間經過諸如RESTful API的方式互相調用。mysql
對於「微服務架構」,你們在互聯網能夠搜索到不少相關的介紹和研究文章來進行學習和了解。也能夠閱讀始祖Martin Fowler
的《Microservices》(中文版翻譯點擊查看),本文不作更多的介紹和描述。web
在簡單介紹了Spring Cloud
和微服務架構以後,下面迴歸本文的主旨內容,如何使用Spring Cloud
來實現服務治理。redis
因爲Spring Cloud
爲服務治理作了一層抽象接口,因此在Spring Cloud
應用中能夠支持多種不一樣的服務治理框架,好比:Netflix Eureka
、Consul
、Zookeeper
。在Spring Cloud
服務治理抽象層的做用下,咱們能夠無縫地切換服務治理實現,而且不影響任何其餘的服務註冊、服務發現、服務調用等邏輯。spring
因此,下面咱們經過Eureka這種種服務治理的實現來體會Spring Cloud
這一層抽象所帶來的好處。
下一篇介紹基於Consul
的服務註冊與調用。sql
首先,咱們來嘗試使用Spring Cloud Eureka
來實現服務治理。數據庫
Spring Cloud Eureka
是Spring Cloud Netflix
項目下的服務治理模塊。而Spring Cloud Netflix
項目是Spring Cloud
的子項目之一,主要內容是對Netflix
公司一系列開源產品的包裝,它爲Spring Boot
應用提供了自配置的Netflix OSS
整合。經過一些簡單的註解,開發者就能夠快速的在應用中配置一下經常使用模塊並構建龐大的分佈式系統。它主要提供的模塊包括:服務發現(Eureka
),斷路器(Hystrix
),智能路由(Zuul
),客戶端負載均衡(Ribbon
)等。apache
下面,就來具體看看如何使用Spring Cloud Eureka
實現服務治理,這裏使用eureka-server
爲服務註冊中心工程、eureka-provider
服務提供者工程、eureka-consumer
服務消費者工程。
環境:
windows jdk 8 maven 3.0 IDEA
首先構建父工程,引入父工程依賴:
<?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> <parent> <groupId>cn.zhangbox</groupId> <artifactId>spring-cloud-study</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>cn.zhangbox</groupId> <artifactId>spring-cloud-eureka</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <!--子模塊--> <modules> <module>eureka-server</module> <module>eureka-provider</module> <module>eureka-consumer</module> </modules> </project>
父工程取名爲:spring-cloud-eureka
構建子工程,分別建立工程名爲:eureka-server
、eureka-provider
、eureka-consumer
並在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> <parent> <groupId>cn.zhangbox</groupId> <artifactId>spring-cloud-eureka</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>cn.zhangbox</groupId> <artifactId>eureka-server</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>eureka-server</name> <description>Spring Cloud In Action</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!-- 引入eureka服務端依賴start --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <!-- 引入eureka服務端依賴end --> </dependencies> <!-- 添加cloud 依賴start --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- 添加cloud 依賴end --> <!-- 添加maven構建插件start --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!-- 添加maven構建插件end --> </project>
<?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> <parent> <groupId>cn.zhangbox</groupId> <artifactId>spring-cloud-eureka</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>cn.zhangbox</groupId> <artifactId>eureka-provider</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>eureka-provider</name> <description>this project for Spring Boot</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!-- 版本控制 --> <commons-lang3.version>3.4</commons-lang3.version> <commons-codec.version>1.10</commons-codec.version> <mybatis-spring-boot.version>1.2.0</mybatis-spring-boot.version> <lombok.version>1.16.14</lombok.version> <fastjson.version>1.2.41</fastjson.version> <druid.version>1.1.2</druid.version> </properties> <repositories> <!-- 阿里私服 --> <repository> <id>aliyunmaven</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <!-- mybatis核心包 start --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>${mybatis-spring-boot.version}</version> </dependency> <!-- mybatis核心包 end --> <!-- 添加eureka支持start --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <!-- 添加eureka支持start --> <!-- SpringWEB核心包 start --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- SpringWEB核心包 end --> <!-- Swagger核心包 start --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <!-- Swagger核心包 end --> <!-- mysql驅動核心包 start --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- mysql驅動核心包 end --> <!-- sprigTest核心包 start --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- sprigTest核心包 end --> <!-- commons工具核心包 start --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> </dependency> <!-- commons工具核心包 end --> <!-- fastjson核心包 start --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- fastjson核心包 end --> <!-- druid核心包 start --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>${druid.version}</version> </dependency> <!-- druid核心包 end --> <!-- lombok核心包 start --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> <!-- lombok核心包 end --> </dependencies> <!-- 添加cloud 依賴start --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- 添加cloud 依賴end --> <build> <finalName>eureka-provider</finalName> <plugins> <!-- 添加maven構建插件start --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 添加maven構建插件end --> </plugins> </build> </project>
<?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> <parent> <groupId>cn.zhangbox</groupId> <artifactId>spring-cloud-eureka</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>cn.zhangbox</groupId> <artifactId>eureka-consumer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>eureka-consumer</name> <description>this project for Spring Boot</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!-- 版本控制 --> <commons-lang3.version>3.4</commons-lang3.version> <commons-codec.version>1.10</commons-codec.version> <mybatis-spring-boot.version>1.2.0</mybatis-spring-boot.version> <lombok.version>1.16.14</lombok.version> <fastjson.version>1.2.41</fastjson.version> <druid.version>1.1.2</druid.version> </properties> <repositories> <!-- 阿里私服 --> <repository> <id>aliyunmaven</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <!-- 添加eureka支持start --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <!-- 添加eureka支持start --> <!-- 添加feign支持start --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> <!-- 添加feign支持end --> <!-- SpringWEB核心包 start --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- SpringWEB核心包 end --> <!-- Swagger核心包 start --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <!-- Swagger核心包 end --> <!-- sprigTest核心包 start --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- sprigTest核心包 end --> <!-- commons工具核心包 start --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> </dependency> <!-- commons工具核心包 end --> <!-- fastjson核心包 start --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- fastjson核心包 end --> <!-- lombok核心包 start --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> <!-- lombok核心包 end --> </dependencies> <!-- 添加cloud 依賴start --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- 添加cloud 依賴end --> <build> <finalName>eureka-provider</finalName> <plugins> <!-- 添加maven構建插件start --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!-- 添加maven構建插件end --> </plugins> </build> </project>
工程構建完成。
首先:在eureka-server
工程下resource
目錄下添加application.yml
文件並加入如下配置:
#工程名稱 spring: application: name: eureka-server #選擇哪個環境的配置 #這裏能夠在每一個環境配置redis,數據庫(mysql),消息(kafka)等相關的組件的配置 profiles: active: dev #配置eureka註冊中心 eureka: #server: #配置關閉自我保護模式 #enableSelfPreservation: false #配置Eureka Server清理無效節點的時間間隔 #eviction-interval-timer-in-ms: 4000 instance: #配置與此實例相關聯的主機名,是其餘實例能夠用來進行請求的準確名稱 hostname: eureka-server #顯示服務ip地址 preferIpAddress: true #獲取服務的ip和端口 instanceId: ${spring.cloud.client.ipAddress}:${server.port} client: #配置不將本身註冊到eureka註冊中心 register-with-eureka: false #配置此客戶端不獲取eureka服務器註冊表上的註冊信息 fetch-registry: false serviceUrl: #配置默認節點有信息,這裏是獲取本機的ip和端口來實現,若是不配置,默認會找8761端口,這裏配置的是1001端口,所以會報錯 defaultZone: http://${spring.cloud.client.ipAddress}:${server.port}/eureka/ #文檔塊區分爲三個--- --- server: port: 1001 spring: profiles: dev #日誌 logging: config: classpath:log/logback.xml path: log/eureka-server #文檔塊區分爲三個--- --- server: port: 1002 spring: profiles: test #日誌 logging: config: classpath:log/logback.xml path: usr/eureka-server/log/eureka-server #文檔塊區分爲三個--- --- server: port: 1003 spring: profiles: prod #日誌 logging: config: classpath:log/logback.xml path: usr/eureka-server/log/eureka-server
這裏日誌的配置不在詳細說明,不知道怎麼配置能夠參考這篇文章:
SpringBoot進階教程 | 第二篇:日誌組件logback實現日誌分級打印
其次:建立核心啓動類:
@EnableEurekaServer//加上此註解表示將此工程啓動後爲註冊中心 @SpringBootApplication public class EurekaServerApplication { public static void main(String[] args) { new SpringApplicationBuilder(EurekaServerApplication.class).web(true).run(args); } }
最後:啓動項目,看到以下日誌打印信息:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2018-07-17 15:05:53.541 INFO 7080 --- [ main] c.z.eureka.EurekaServerApplication : The following profiles are active: dev 2018-07-17 15:05:53.588 INFO 7080 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5b22b970: startup date [Tue Jul 17 15:05:53 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3af0a9da 2018-07-17 15:05:55.126 INFO 7080 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=cd854175-7c7f-3c0f-8597-c3d23f037104 2018-07-17 15:05:55.147 INFO 7080 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2018-07-17 15:05:55.247 INFO 7080 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.netflix.metrics.MetricsInterceptorConfiguration$MetricsRestTemplateConfiguration' of type [org.springframework.cloud.netflix.metrics.MetricsInterceptorConfiguration$MetricsRestTemplateConfiguration$$EnhancerBySpringCGLIB$$a90c774] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-17 15:05:55.259 INFO 7080 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f47e2430] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-17 15:05:55.658 INFO 7080 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 1001 (http) 2018-07-17 15:05:55.670 INFO 7080 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2018-07-17 15:05:55.672 INFO 7080 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14 2018-07-17 15:05:55.946 INFO 7080 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2018-07-17 15:05:55.947 INFO 7080 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2359 ms 2018-07-17 15:05:57.669 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*] 2018-07-17 15:05:57.680 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-07-17 15:05:57.681 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-07-17 15:05:57.681 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-07-17 15:05:57.681 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-07-17 15:05:57.682 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestTraceFilter' to: [/*] 2018-07-17 15:05:57.683 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'servletContainer' to urls: [/eureka/*] 2018-07-17 15:05:57.683 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*] 2018-07-17 15:05:57.683 INFO 7080 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-07-17 15:05:58.056 INFO 7080 --- [ost-startStop-1] c.s.j.s.i.a.WebApplicationImpl : Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM' 2018-07-17 15:05:58.376 INFO 7080 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson 2018-07-17 15:05:58.378 INFO 7080 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson 2018-07-17 15:05:58.617 INFO 7080 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml 2018-07-17 15:05:58.618 INFO 7080 --- [ost-startStop-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml 2018-07-17 15:06:00.945 INFO 7080 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5b22b970: startup date [Tue Jul 17 15:05:53 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3af0a9da 2018-07-17 15:06:02.200 INFO 7080 --- [ 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) 2018-07-17 15:06:02.202 INFO 7080 --- [ 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) 2018-07-17 15:06:02.209 INFO 7080 --- [ 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>) 2018-07-17 15:06:02.209 INFO 7080 --- [ 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>) 2018-07-17 15:06:02.257 INFO 7080 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:06:02.258 INFO 7080 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:06:02.590 INFO 7080 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:06:04.453 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/logfile || /logfile.json],methods=[GET || HEAD]}" onto public void org.springframework.boot.actuate.endpoint.mvc.LogFileMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException 2018-07-17 15:06:04.454 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/archaius || /archaius.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.456 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal) 2018-07-17 15:06:04.457 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String) 2018-07-17 15:06:04.458 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.460 INFO 7080 --- [ 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() 2018-07-17 15:06:04.461 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/service-registry/instance-status],methods=[GET]}" onto public org.springframework.http.ResponseEntity org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint.getStatus() 2018-07-17 15:06:04.461 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/service-registry/instance-status],methods=[POST]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint.setStatus(java.lang.String) 2018-07-17 15:06:04.462 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.463 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String) 2018-07-17 15:06:04.463 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.466 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.468 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String) 2018-07-17 15:06:04.468 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map<java.lang.String, java.lang.String>) 2018-07-17 15:06:04.468 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.469 INFO 7080 --- [ 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() 2018-07-17 15:06:04.471 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.472 INFO 7080 --- [ 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>) 2018-07-17 15:06:04.473 INFO 7080 --- [ 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() 2018-07-17 15:06:04.473 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.474 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/features || /features.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.474 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.475 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String) 2018-07-17 15:06:04.476 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.478 INFO 7080 --- [ 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() 2018-07-17 15:06:04.479 INFO 7080 --- [ 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 2018-07-17 15:06:04.480 INFO 7080 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke() 2018-07-17 15:06:04.480 INFO 7080 --- [ 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() 2018-07-17 15:06:04.762 INFO 7080 --- [ main] o.s.ui.freemarker.SpringTemplateLoader : SpringTemplateLoader for FreeMarker: using resource loader [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5b22b970: startup date [Tue Jul 17 15:05:53 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3af0a9da] and template loader path [classpath:/templates/] 2018-07-17 15:06:04.763 INFO 7080 --- [ main] o.s.w.s.v.f.FreeMarkerConfigurer : ClassTemplateLoader for Spring macros added to FreeMarker configuration 2018-07-17 15:06:06.416 WARN 7080 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-17 15:06:06.440 INFO 7080 --- [ 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. 2018-07-17 15:06:06.871 WARN 7080 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-17 15:06:06.872 INFO 7080 --- [ 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. 2018-07-17 15:06:07.545 INFO 7080 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING 2018-07-17 15:06:07.746 INFO 7080 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1 2018-07-17 15:06:07.746 INFO 7080 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data. 2018-07-17 15:06:07.996 INFO 7080 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1531811167765 with initial instances count: 0 2018-07-17 15:06:08.140 INFO 7080 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initializing ... 2018-07-17 15:06:08.143 WARN 7080 --- [ main] c.n.eureka.cluster.PeerEurekaNodes : The replica size seems to be empty. Check the route 53 DNS Registry 2018-07-17 15:06:08.159 INFO 7080 --- [ main] c.n.e.registry.AbstractInstanceRegistry : Finished initializing remote region registries. All known remote regions: [] 2018-07-17 15:06:08.159 INFO 7080 --- [ main] c.n.eureka.DefaultEurekaServerContext : Initialized 2018-07-17 15:06:08.443 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-07-17 15:06:08.458 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure 2018-07-17 15:06:08.461 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure 2018-07-17 15:06:08.462 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure 2018-07-17 15:06:08.463 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'restartEndpoint' has been autodetected for JMX exposure 2018-07-17 15:06:08.464 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'serviceRegistryEndpoint' has been autodetected for JMX exposure 2018-07-17 15:06:08.465 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure 2018-07-17 15:06:08.468 INFO 7080 --- [ 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] 2018-07-17 15:06:08.492 INFO 7080 --- [ 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] 2018-07-17 15:06:08.574 INFO 7080 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'serviceRegistryEndpoint': registering with JMX server as MBean [org.springframework.cloud.client.serviceregistry.endpoint:name=serviceRegistryEndpoint,type=ServiceRegistryEndpoint] 2018-07-17 15:06:08.586 INFO 7080 --- [ 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] 2018-07-17 15:06:08.603 INFO 7080 --- [ 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=5b22b970,type=ConfigurationPropertiesRebinder] 2018-07-17 15:06:08.608 INFO 7080 --- [ 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] 2018-07-17 15:06:08.609 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Registering beans for JMX exposure on startup 2018-07-17 15:06:08.979 INFO 7080 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0 2018-07-17 15:06:08.980 INFO 7080 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application eureka-server with eureka with status UP 2018-07-17 15:06:08.983 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'auditEventsEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=auditEventsEndpoint] 2018-07-17 15:06:08.991 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'featuresEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=featuresEndpoint] 2018-07-17 15:06:08.998 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'requestMappingEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=requestMappingEndpoint] 2018-07-17 15:06:09.000 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'environmentEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=environmentEndpoint] 2018-07-17 15:06:09.002 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'healthEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=healthEndpoint] 2018-07-17 15:06:09.005 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'beansEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=beansEndpoint] 2018-07-17 15:06:09.007 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'infoEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=infoEndpoint] 2018-07-17 15:06:09.010 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'loggersEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=loggersEndpoint] 2018-07-17 15:06:09.017 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'metricsEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=metricsEndpoint] 2018-07-17 15:06:09.019 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'traceEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=traceEndpoint] 2018-07-17 15:06:09.021 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'dumpEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=dumpEndpoint] 2018-07-17 15:06:09.023 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'autoConfigurationReportEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=autoConfigurationReportEndpoint] 2018-07-17 15:06:09.026 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'configurationPropertiesReportEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=configurationPropertiesReportEndpoint] 2018-07-17 15:06:09.028 INFO 7080 --- [ main] o.s.b.a.e.jmx.EndpointMBeanExporter : Located managed bean 'archaiusEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=archaiusEndpoint] 2018-07-17 15:06:09.039 INFO 7080 --- [ Thread-42] o.s.c.n.e.server.EurekaServerBootstrap : Setting the eureka configuration.. 2018-07-17 15:06:09.040 INFO 7080 --- [ Thread-42] o.s.c.n.e.server.EurekaServerBootstrap : Eureka data center value eureka.datacenter is not set, defaulting to default 2018-07-17 15:06:09.040 INFO 7080 --- [ Thread-42] o.s.c.n.e.server.EurekaServerBootstrap : Eureka environment value eureka.environment is not set, defaulting to test 2018-07-17 15:06:09.109 INFO 7080 --- [ Thread-42] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false 2018-07-17 15:06:09.111 INFO 7080 --- [ Thread-42] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context 2018-07-17 15:06:09.111 INFO 7080 --- [ Thread-42] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node 2018-07-17 15:06:09.111 INFO 7080 --- [ Thread-42] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1 2018-07-17 15:06:09.111 INFO 7080 --- [ Thread-42] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP 2018-07-17 15:06:09.118 INFO 7080 --- [ Thread-42] e.s.EurekaServerInitializerConfiguration : Started Eureka Server 2018-07-17 15:06:09.181 INFO 7080 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 1001 (http) 2018-07-17 15:06:09.183 INFO 7080 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 1001 2018-07-17 15:06:09.189 INFO 7080 --- [ main] c.z.eureka.EurekaServerApplication : Started EurekaServerApplication in 17.898 seconds (JVM running for 21.087) 2018-07-17 15:06:13.112 INFO 7080 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms 2018-07-17 15:06:17.112 INFO 7080 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms 2018-07-17 15:06:21.173 INFO 7080 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 61ms 2018-07-17 15:06:21.385 INFO 7080 --- [nio-1001-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2018-07-17 15:06:21.386 INFO 7080 --- [nio-1001-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2018-07-17 15:06:21.435 INFO 7080 --- [nio-1001-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 49 ms 2018-07-17 15:06:22.438 WARN 7080 --- [nio-1001-exec-2] c.n.e.registry.AbstractInstanceRegistry : DS: Registry: lease doesn't exist, registering resource: EUREKA-PROVIDER - 10.25.26.144:8080 2018-07-17 15:06:22.439 WARN 7080 --- [nio-1001-exec-2] c.n.eureka.resources.InstanceResource : Not Found (Renew): EUREKA-PROVIDER - 10.25.26.144:8080 2018-07-17 15:06:22.564 INFO 7080 --- [nio-1001-exec-3] c.n.e.registry.AbstractInstanceRegistry : Registered instance EUREKA-PROVIDER/10.25.26.144:8080 with status UP (replication=false) 2018-07-17 15:06:25.173 INFO 7080 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms 2018-07-17 15:06:29.173 INFO 7080 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry : Running the evict task with compensationTime 0ms 2018-07-17 15:06:31.169 WARN 7080 --- [nio-1001-exec-4] c.n.e.registry.AbstractInstanceRegistry : DS: Registry: lease doesn't exist, registering resource: UNKNOWN - 10.25.26.144:8081 2018-07-17 15:06:31.169 WARN 7080 --- [nio-1001-exec-4] c.n.eureka.resources.InstanceResource : Not Found (Renew): UNKNOWN - 10.25.26.144:8081 2018-07-17 15:06:31.198 INFO 7080 --- [nio-1001-exec-6] c.n.e.registry.AbstractInstanceRegistry : Registered instance UNKNOWN/10.25.26.144:8081 with status UP (replication=false)
至此eureka
註冊中心建立完成,瀏覽器輸入地址:http://localhost:1001/
能夠看到以下頁面,表示服務啓動OK
圖片.png
這裏這看到尚未服務暴露出來,是由於還沒建立服務提供者工程。
這裏服務提供者是使用以前SpringBoot進階教程 | 第三篇:整合Druid鏈接池以及Druid監控改造而來,這裏同樣的部分就再也不重複說明,下面將說明新增的部分。
首先:修改application.yml配置爲以下:
#公共配置 server: port: 80 tomcat: uri-encoding: UTF-8 spring: application: #服務名稱,更關鍵,使用feign進行服務消費將以此爲依據 name: eureka-provider #激活哪個環境的配置文件 profiles: active: dev #鏈接池配置 datasource: driver-class-name: com.mysql.jdbc.Driver # 使用druid數據源 type: com.alibaba.druid.pool.DruidDataSource druid: # 配置測試查詢語句 validationQuery: SELECT 1 FROM DUAL # 初始化大小,最小,最大 initialSize: 10 minIdle: 10 maxActive: 200 # 配置一個鏈接在池中最小生存的時間,單位是毫秒 minEvictableIdleTimeMillis: 180000 testOnBorrow: false testWhileIdle: true removeAbandoned: true removeAbandonedTimeout: 1800 logAbandoned: true # 打開PSCache,而且指定每一個鏈接上PSCache的大小 poolPreparedStatements: true maxOpenPreparedStatements: 100 # 配置監控統計攔截的filters,去掉後監控界面sql沒法統計,'wall'用於防火牆 filters: stat,wall,log4j # 經過connectProperties屬性來打開mergeSql功能;慢SQL記錄 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 #配置eureka獲取服務地址,這裏使用的是本地註冊中心 eureka: client: serviceUrl: defaultZone: http://localhost:1001/eureka/ #配置Swagger相關信息 instance: prefer-ip-address: true instanceId: ${spring.cloud.client.ipAddress}:${server.port} status-page-url: http://${spring.cloud.client.ipAddress}:${server.port}/swagger-ui.html # ${server.port}爲該服務的端口號 #mybatis mybatis: # 實體類掃描 type-aliases-package: cn.zhangbox.springboot.entity # 配置映射文件位置 mapper-locations: classpath:mapper/*.xml # 開啓駝峯匹配 mapUnderscoreToCamelCase: true --- #開發環境配置 server: #端口 port: 8080 spring: profiles: dev # 數據源配置 datasource: url: jdbc:mysql://101.132.66.175:3306/student?useUnicode=true&characterEncoding=utf8&useSSL=false&tinyInt1isBit=true username: root password: 123456 #日誌 logging: config: classpath:log/logback.xml path: log/eureka-provider --- #測試環境配置 server: #端口 port: 80 spring: profiles: test # 數據源配置 datasource: url: jdbc:mysql://127.0.0.1:3306/eureka-provider?useUnicode=true&characterEncoding=utf8&useSSL=false&tinyInt1isBit=true username: root password: 123456 #日誌 logging: config: classpath:log/logback.xml path: /home/log/eureka-provider --- #生產環境配置 server: #端口 port: 8080 spring: profiles: prod # 數據源配置 datasource: url: jdbc:mysql://127.0.0.1:3306/eureka-provider?useUnicode=true&characterEncoding=utf8&useSSL=false&tinyInt1isBit=true username: root password: 123456 #日誌 logging: config: classpath:log/logback.xml path: /home/log/eureka-provider
其次:在config
目錄下增長SwaggerConfig
類加入如下代碼:
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket userApi() { Docket docket = new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("cn.zhangbox.eureka.provider.controller"))//過濾的接口,有這掃描纔會看到接口信息 .paths(PathSelectors.any()) .build(); return docket; } private ApiInfo apiInfo() { return new ApiInfoBuilder().title("eureka服務端提供者接口平臺").description("服務相關數據接口") .termsOfServiceUrl("http://www.zhang.box.cn/").contact("技術開發部") .license("Licence Version 1.0").licenseUrl("#").version("1.0").build(); } }
這裏若是不會使用swagger
的整合能夠參考這篇文章:
SpringBoot非官方教程 | 第十一篇:SpringBoot集成swagger2,構建優雅的Restful API
接着:建立核心啓動類:
@EnableDiscoveryClient //使用該註解將註冊服務到eureka @SpringBootApplication @MapperScan("cn.zhangbox.eureka.provider.dao")//配置mybatis接口包掃描 public class EurekaProviderApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(EurekaProviderApplication.class, args); } }
最後:啓動項目,看到以下日誌打印信息:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2018-07-17 15:29:29.267 INFO 12312 --- [ main] c.z.e.p.EurekaProviderApplication : The following profiles are active: dev 2018-07-17 15:29:29.295 INFO 12312 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@51827393: startup date [Tue Jul 17 15:29:29 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4241e0f4 2018-07-17 15:29:30.902 INFO 12312 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'filterRegistrationBean' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=druidDBConfig; factoryMethodName=filterRegistrationBean; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [cn/zhangbox/eureka/provider/config/DruidDBConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.alibaba.druid.spring.boot.autoconfigure.stat.DruidWebStatFilterConfiguration; factoryMethodName=filterRegistrationBean; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidWebStatFilterConfiguration.class]] 2018-07-17 15:29:31.251 INFO 12312 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=608dd1ca-975a-302d-aa26-cd8dca769951 2018-07-17 15:29:31.277 INFO 12312 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2018-07-17 15:29:31.389 INFO 12312 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$d6e9b9c7] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-17 15:29:31.449 INFO 12312 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f303bcc4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-17 15:29:32.818 INFO 12312 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2018-07-17 15:29:32.829 INFO 12312 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2018-07-17 15:29:32.830 INFO 12312 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14 2018-07-17 15:29:33.250 INFO 12312 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2018-07-17 15:29:33.250 INFO 12312 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3955 ms 2018-07-17 15:29:33.605 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'statViewServlet' to [/druid/*] 2018-07-17 15:29:33.607 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-07-17 15:29:33.608 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'statViewServlet' to [/druid/*] 2018-07-17 15:29:33.608 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet statViewServlet was not registered (possibly already registered?) 2018-07-17 15:29:33.614 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-07-17 15:29:33.614 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-07-17 15:29:33.614 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-07-17 15:29:33.614 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-07-17 15:29:33.615 INFO 12312 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webStatFilter' to urls: [/*] 2018-07-17 15:29:36.473 INFO 12312 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/student/list],methods=[GET]}" onto public java.lang.String cn.zhangbox.eureka.provider.controller.StudentConteroller.list(java.lang.String,java.lang.Integer,org.springframework.ui.ModelMap) 2018-07-17 15:29:36.475 INFO 12312 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/api-docs],methods=[GET],produces=[application/json || application/hal+json]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest) 2018-07-17 15:29:36.478 INFO 12312 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/ui]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration() 2018-07-17 15:29:36.479 INFO 12312 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources]}" onto org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() 2018-07-17 15:29:36.480 INFO 12312 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/security]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration() 2018-07-17 15:29:36.483 INFO 12312 --- [ 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) 2018-07-17 15:29:36.483 INFO 12312 --- [ 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) 2018-07-17 15:29:37.292 INFO 12312 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@51827393: startup date [Tue Jul 17 15:29:29 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4241e0f4 2018-07-17 15:29:37.651 INFO 12312 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:29:37.651 INFO 12312 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:29:37.717 INFO 12312 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:29:38.371 WARN 12312 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-17 15:29:38.385 INFO 12312 --- [ 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. 2018-07-17 15:29:38.390 WARN 12312 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-17 15:29:38.391 INFO 12312 --- [ 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. 2018-07-17 15:29:38.619 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-07-17 15:29:38.622 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'statFilter' has been autodetected for JMX exposure 2018-07-17 15:29:38.622 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure 2018-07-17 15:29:38.631 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure 2018-07-17 15:29:38.633 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure 2018-07-17 15:29:38.634 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure 2018-07-17 15:29:38.638 INFO 12312 --- [ 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] 2018-07-17 15:29:38.942 INFO 12312 --- [ 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] 2018-07-17 15:29:38.955 INFO 12312 --- [ 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=51827393,type=ConfigurationPropertiesRebinder] 2018-07-17 15:29:38.963 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.alibaba.druid.spring.boot.autoconfigure:name=dataSource,type=DruidDataSourceWrapper] 2018-07-17 15:29:38.965 INFO 12312 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'statFilter': registering with JMX server as MBean [com.alibaba.druid.filter.stat:name=statFilter,type=StatFilter] 2018-07-17 15:29:39.410 INFO 12312 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0 2018-07-17 15:29:39.418 INFO 12312 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING 2018-07-17 15:29:39.548 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1 2018-07-17 15:29:40.130 INFO 12312 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson 2018-07-17 15:29:40.131 INFO 12312 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson 2018-07-17 15:29:40.256 INFO 12312 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml 2018-07-17 15:29:40.256 INFO 12312 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml 2018-07-17 15:29:41.457 INFO 12312 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true 2018-07-17 15:29:41.579 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2018-07-17 15:29:42.334 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200 2018-07-17 15:29:42.336 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30 2018-07-17 15:29:42.339 INFO 12312 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4 2018-07-17 15:29:42.344 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1531812582343 with initial instances count: 0 2018-07-17 15:29:42.364 INFO 12312 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application eureka-provider with eureka with status UP 2018-07-17 15:29:42.365 INFO 12312 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1531812582365, current=UP, previous=STARTING] 2018-07-17 15:29:42.367 INFO 12312 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA-PROVIDER/10.25.26.144:8080: registering service... 2018-07-17 15:29:42.369 INFO 12312 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647 2018-07-17 15:29:42.369 INFO 12312 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed 2018-07-17 15:29:42.450 INFO 12312 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s) 2018-07-17 15:29:42.575 INFO 12312 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA-PROVIDER/10.25.26.144:8080 - registration status: 204 2018-07-17 15:29:42.741 INFO 12312 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references 2018-07-17 15:29:42.849 WARN 12312 --- [ main] s.d.s.w.r.p.ParameterDataTypeReader : Trying to infer dataType org.springframework.ui.ModelMap 2018-07-17 15:29:43.087 INFO 12312 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2018-07-17 15:29:43.088 INFO 12312 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8080 2018-07-17 15:29:43.094 INFO 12312 --- [ main] c.z.e.p.EurekaProviderApplication : Started EurekaProviderApplication in 16.419 seconds (JVM running for 21.462)
至此eureka-provider
服務提供者建立完成,瀏覽器輸入地址:http://localhost:1001/
能夠看到以下頁面,表示服務註冊OK
圖片.png
點擊Status
下的ip
後能夠跳轉看到swagger
的頁面並但是測試服務提供者的接口,以下:
圖片.png
這裏構建的工程名爲eureka-consumer
,上文已經構建了工程可是沒有建立目錄,這裏只須要在java目錄下建立config
、controller
,service
,包便可,這裏服務的消費是經過feign
來進行服務調用的,後面會有專門以篇文章來說feign
。
首先:在eureka-consumer
工程下resource
目錄下添加application.yml
文件並加入如下配置:
#公共配置 server: port: 80 tomcat: uri-encoding: UTF-8 spring: #服務名稱,更關鍵,使用feign進行服務消費將以此爲依據 application: name: eureka-consumer #激活哪個環境的配置文件 profiles: active: dev #配置eureka獲取服務地址,這裏使用的是本地註冊中心 eureka: client: serviceUrl: defaultZone: http://localhost:1001/eureka/ #配置instance相關信息 instance: prefer-ip-address: true instanceId: ${spring.cloud.client.ipAddress}:${server.port} status-page-url: http://${spring.cloud.client.ipAddress}:${server.port}/swagger-ui.html # ${server.port}爲該服務的端口號 --- #開發環境配置 server: #端口 port: 8081 spring: profiles: dev #日誌 logging: config: classpath:log/logback.xml path: log/eureka-consumer --- #測試環境配置 server: #端口 port: 8082 spring: profiles: test #日誌 logging: config: classpath:log/logback.xml path: /home/log/eureka-consumer --- #生產環境配置 server: #端口 port: 8083 spring: profiles: prod #日誌 logging: config: classpath:log/logback.xml path: /home/log/eureka-consumer
其次:在config
目錄下增長SwaggerConfig
類加入如下代碼:
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket userApi() { Docket docket = new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("cn.zhangbox.eureka.consumer.controller"))//過濾的接口,有這掃描纔會看到接口信息 .paths(PathSelectors.any()) .build(); return docket; } private ApiInfo apiInfo() { return new ApiInfoBuilder().title("eureka服務端消費者接口平臺").description("服務相關數據接口") .termsOfServiceUrl("http://www.zhang.box.cn/").contact("技術開發部") .license("Licence Version 1.0").licenseUrl("#").version("1.0").build(); } }
接着:在service
包下建立StudentConsumerService
類並加入如下代碼:
@FeignClient(value = "eureka-provider") public interface StudentConsumerService { /** * 查詢全部的學生信息 * * @param sname * @param age * @return */ @RequestMapping(value = "/student/list",method = RequestMethod.GET) String getStudentList(@RequestParam(value = "sname") String sname, @RequestParam(value = "age") Integer age); }
而後:在controller
包下建立StudentConteroller
並加入以下代碼:
@Controller @RequestMapping("/student") @Api(value = "eureka-consumer", description = "學生查詢接口") public class StudentConteroller { private static final Logger LOGGER = LoggerFactory.getLogger(StudentConteroller.class); @Autowired StudentConsumerService studentService; /** * 查詢全部的學生信息 * * @param sname * @param age * @param modelMap * @return */ @ResponseBody @GetMapping("/consumer/list") public String list( @ApiParam(value = "學生姓名") @RequestParam(required = false) String sname, @ApiParam(value = "年齡") @RequestParam(required = false) Integer age, ModelMap modelMap) { String json = null; try { json = studentService.getStudentList(sname, age); } catch (Exception e) { e.printStackTrace(); modelMap.put("ren_code", "0"); modelMap.put("ren_msg", "查詢失敗===>" + e); LOGGER.error("查詢失敗===>" + e); json = JSON.toJSONString(modelMap); } return json; } }
接着:建立核心啓動類:
@EnableFeignClients//開啓Feign調用接口 @EnableDiscoveryClient//開啓客戶端服務,沒有這個註解會報Feign找不到對應服務的錯誤 @SpringBootApplication public class EurekaConsumerApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(EurekaConsumerApplication.class, args); } }
最後:啓動項目,看到以下日誌打印信息:
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2018-07-17 15:56:10.446 INFO 9400 --- [ main] c.z.e.c.EurekaConsumerApplication : The following profiles are active: dev 2018-07-17 15:56:10.480 INFO 9400 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7a799159: startup date [Tue Jul 17 15:56:10 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3b8f0a79 2018-07-17 15:56:11.536 INFO 9400 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=6ee65f72-d692-3f45-bb25-4625a69b17da 2018-07-17 15:56:11.558 INFO 9400 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2018-07-17 15:56:11.590 INFO 9400 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'cn.zhangbox.eureka.consumer.service.StudentConsumerService' of type [org.springframework.cloud.netflix.feign.FeignClientFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-17 15:56:11.640 INFO 9400 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$89a7f8be] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-17 15:56:12.196 INFO 9400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http) 2018-07-17 15:56:12.265 INFO 9400 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2018-07-17 15:56:12.271 INFO 9400 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14 2018-07-17 15:56:12.658 INFO 9400 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2018-07-17 15:56:12.658 INFO 9400 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2178 ms 2018-07-17 15:56:12.841 INFO 9400 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-07-17 15:56:12.847 INFO 9400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-07-17 15:56:12.881 INFO 9400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-07-17 15:56:12.881 INFO 9400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-07-17 15:56:12.881 INFO 9400 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-07-17 15:56:12.985 INFO 9400 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6723610b: startup date [Tue Jul 17 15:56:12 GMT+08:00 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7a799159 2018-07-17 15:56:13.039 INFO 9400 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2018-07-17 15:56:13.898 INFO 9400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/student/consumer/list],methods=[GET]}" onto public java.lang.String cn.zhangbox.eureka.consumer.controller.StudentConteroller.list(java.lang.String,java.lang.Integer,org.springframework.ui.ModelMap) 2018-07-17 15:56:13.900 INFO 9400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/api-docs],methods=[GET],produces=[application/json || application/hal+json]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest) 2018-07-17 15:56:13.902 INFO 9400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/ui]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration() 2018-07-17 15:56:13.903 INFO 9400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources]}" onto org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() 2018-07-17 15:56:13.904 INFO 9400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources/configuration/security]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration() 2018-07-17 15:56:13.907 INFO 9400 --- [ 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) 2018-07-17 15:56:13.908 INFO 9400 --- [ 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) 2018-07-17 15:56:14.482 INFO 9400 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7a799159: startup date [Tue Jul 17 15:56:10 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@3b8f0a79 2018-07-17 15:56:14.555 INFO 9400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:56:14.555 INFO 9400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:56:14.643 INFO 9400 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-17 15:56:15.188 WARN 9400 --- [ main] o.s.c.n.a.ArchaiusAutoConfiguration : No spring.application.name found, defaulting to 'application' 2018-07-17 15:56:15.218 WARN 9400 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-17 15:56:15.218 INFO 9400 --- [ 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. 2018-07-17 15:56:15.223 WARN 9400 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-17 15:56:15.223 INFO 9400 --- [ 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. 2018-07-17 15:56:15.373 INFO 9400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-07-17 15:56:15.383 INFO 9400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure 2018-07-17 15:56:15.385 INFO 9400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure 2018-07-17 15:56:15.387 INFO 9400 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure 2018-07-17 15:56:15.391 INFO 9400 --- [ 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] 2018-07-17 15:56:15.428 INFO 9400 --- [ 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] 2018-07-17 15:56:15.442 INFO 9400 --- [ 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=7a799159,type=ConfigurationPropertiesRebinder] 2018-07-17 15:56:15.562 INFO 9400 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0 2018-07-17 15:56:15.570 INFO 9400 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING 2018-07-17 15:56:15.634 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1 2018-07-17 15:56:16.225 INFO 9400 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson 2018-07-17 15:56:16.225 INFO 9400 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson 2018-07-17 15:56:16.345 INFO 9400 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml 2018-07-17 15:56:16.346 INFO 9400 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml 2018-07-17 15:56:16.826 INFO 9400 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration 2018-07-17 15:56:16.965 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false 2018-07-17 15:56:16.966 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 2018-07-17 15:56:16.966 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 2018-07-17 15:56:16.966 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false 2018-07-17 15:56:16.966 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 2018-07-17 15:56:16.967 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true 2018-07-17 15:56:16.967 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2018-07-17 15:56:17.184 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200 2018-07-17 15:56:17.186 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30 2018-07-17 15:56:17.189 INFO 9400 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4 2018-07-17 15:56:17.195 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1531814177194 with initial instances count: 1 2018-07-17 15:56:17.218 INFO 9400 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application unknown with eureka with status UP 2018-07-17 15:56:17.219 INFO 9400 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1531814177219, current=UP, previous=STARTING] 2018-07-17 15:56:17.221 INFO 9400 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/10.25.26.144:8081: registering service... 2018-07-17 15:56:17.222 INFO 9400 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647 2018-07-17 15:56:17.223 INFO 9400 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed 2018-07-17 15:56:17.261 INFO 9400 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/10.25.26.144:8081 - registration status: 204 2018-07-17 15:56:17.280 INFO 9400 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s) 2018-07-17 15:56:17.305 INFO 9400 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references 2018-07-17 15:56:17.379 WARN 9400 --- [ main] s.d.s.w.r.p.ParameterDataTypeReader : Trying to infer dataType org.springframework.ui.ModelMap 2018-07-17 15:56:17.614 INFO 9400 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http) 2018-07-17 15:56:17.616 INFO 9400 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8081 2018-07-17 15:56:17.621 INFO 9400 --- [ main] c.z.e.c.EurekaConsumerApplication : Started EurekaConsumerApplication in 9.852 seconds (JVM running for 12.176)
至此eureka-consumer
服務提供者建立完成,瀏覽器輸入地址:http://127.0.0.1:8081/swagger-ui.html
一樣也能夠點擊eureka
控制檯中Application
爲EUREKA-CONSUMER
後Status
下的ip
後能夠跳轉看到swagger
的頁面並但是測試服務消費者的接口,能夠看到以下頁面,並點擊try it out
按鈕,返回了正確的學生信息數據
圖片.png
返回數據以下:
圖片.png
{ "ren_code": "0", "ren_msg": "查詢成功", "studentList": [{ "age": "17", "birth": "2010-07-22", "dept": "王同窗學習成績很不錯", "sex": "1", "sname": "王同窗", "sno": 1 }, { "age": "17", "birth": "2010-07-22", "dept": "李同窗學習成績很不錯", "sex": "1", "sname": "李同窗", "sno": 2 }] }
以上就是spring cloud基於eurka實現分佈式服務註冊與消費的整合流程,是否是很簡單,你也來小試牛刀一把吧。
做者:星緣1314