spring cloud
爲開發人員提供了快速構建分佈式系統的一些工具,包括配置管理、服務發現、斷路器、路由、微代理、事件總線、全局鎖、決策競選、分佈式會話等等。它運行環境簡單,能夠在開發人員的電腦上跑。另外說明spring cloud
是基於springboot
的,因此須要開發中對springboot
有必定的瞭解,若是不瞭解的話能夠看這篇文章:2小時學會springboot。另外對於「微服務架構」 不瞭解的話,能夠經過搜索引擎搜索「微服務架構」瞭解下。html
在以前的全部Spring Boot
相關博文中,都會涉及Spring Boot
工程的建立。而建立的方式多種多樣,這裏,咱們能夠經過Maven
來手工構建或是經過腳手架等方式快速搭建。java
本文咱們將介紹嵌入的Intellij
中的maven
工具,來快速的構建出一個基礎的Spring Cloud
工程。mysql
第一步: 菜單欄中選擇File
=>New
=>Project..
,咱們能夠看到以下圖所示的建立功能窗口。而後,咱們選擇maven
。
react
第二步: 點擊Next
,等待片刻後,咱們能夠看到以下圖所示的工程信息窗口,在這裏咱們能夠編輯咱們想要建立的工程信息。其中,GroupId
是工程的分組id,ArtifactId
是模塊分組id,Version
是當前的版本。GroupId
、ArtifactId
、Version
組合在一塊兒造成一個模塊的座標git
第三步: 點擊Next
,進入最後關於工程物理存儲的一些細節。最後,點擊Finish
就能完成工程的構建了。程序員
工程構建完成web
<?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.cloud.demo</groupId> <artifactId>cloud-demo</artifactId> <version>1.0-SNAPSHOT</version> <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</artifactId> </dependency> <!-- 添加eureka支持start --> <!-- 添加web支持start --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 添加web支持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>
#工程名稱 spring: application: name: cloud-demo #選擇哪個環境的配置 #這裏能夠在每一個環境配置redis,數據庫(mysql),消息(kafka)等相關的組件的配置 profiles: active: dev #配置eureka獲取服務地址,這裏使用的是程序員DD公開的eureka註冊中心,感謝程序員DD提供的註冊中心 eureka: client: serviceUrl: defaultZone: http://eureka.didispace.com/eureka/ #文檔塊區分爲三個--- --- server: port: 8081 spring: profiles: dev #日誌 logging: config: classpath:log/logback.xml path: log/cloud-demo #文檔塊區分爲三個--- --- server: port: 8082 spring: profiles: test #日誌 logging: config: classpath:log/logback.xml path: usr/cloud-demo/log/cloud-demo #文檔塊區分爲三個--- --- server: port: 8083 spring: profiles: prod #日誌 logging: config: classpath:log/logback.xml path: usr/cloud-demo/log/cloud-demo
在工程resources
文件夾下新建文件夾log
,並在該文件夾下建立logback.xml
文件,加入如下配置:redis
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html --> <configuration scan="true" scanPeriod="10 seconds"> <!--繼承spring boot提供的logback配置--> <!--<include resource="org/springframework/boot/logging/logback/base.xml" />--> <!--設置系統日誌目錄--> <property name="APP_DIR" value="cloud-demo" /> <!-- 彩色日誌 --> <!-- 彩色日誌依賴的渲染類 --> <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /> <!-- 彩色日誌格式 --> <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> <!-- 控制檯輸出 --> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <Pattern>${CONSOLE_LOG_PATTERN}</Pattern> <charset>UTF-8</charset> <!-- 此處設置字符集 --> </encoder> <!--此日誌appender是爲開發使用,只配置最底級別,控制檯輸出的日誌級別是大於或等於此級別的日誌信息--> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>debug</level> </filter> </appender> <!-- 時間滾動輸出 level爲 DEBUG 日誌 --> <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在記錄的日誌文件的路徑及文件名 --> <file>${LOG_PATH}/log_debug.log</file> <!--日誌文件輸出格式--> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> <charset>UTF-8</charset> <!-- 此處設置字符集 --> </encoder> <!-- 日誌記錄器的滾動策略,按日期,按大小記錄 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 歸檔的日誌文件的路徑,例現在天是2017-04-26日誌,當前寫的日誌文件路徑爲file節點指定,能夠將此文件與file指定文件路徑設置爲不一樣路徑,從而將當前日誌文件或歸檔日誌文件置不一樣的目錄。 而2017-04-26的日誌文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${LOG_PATH}/debug/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!-- 除按日誌記錄以外,還配置了日誌文件不能超過500M,若超過500M,日誌文件會以索引0開始, 命名日誌文件,例如log-error-2017-04-26.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <!--日誌文件保留天數--> <maxHistory>30</maxHistory> </rollingPolicy> <!-- 此日誌文件只記錄debug級別的 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>debug</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- 時間滾動輸出 level爲 INFO 日誌 --> <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在記錄的日誌文件的路徑及文件名 --> <file>${LOG_PATH}/log_info.log</file> <!--日誌文件輸出格式--> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> <charset>UTF-8</charset> <!-- 此處設置字符集 --> </encoder> <!-- 日誌記錄器的滾動策略,按日期,按大小記錄 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 歸檔的日誌文件的路徑,例現在天是2017-04-26日誌,當前寫的日誌文件路徑爲file節點指定,能夠將此文件與file指定文件路徑設置爲不一樣路徑,從而將當前日誌文件或歸檔日誌文件置不一樣的目錄。 而2017-04-26的日誌文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${LOG_PATH}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!-- 除按日誌記錄以外,還配置了日誌文件不能超過500M,若超過500M,日誌文件會以索引0開始, 命名日誌文件,例如log-error-2017-04-26.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <!--日誌文件保留天數--> <maxHistory>30</maxHistory> </rollingPolicy> <!-- 此日誌文件只記錄info級別的 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>info</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- 時間滾動輸出 level爲 WARN 日誌 --> <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在記錄的日誌文件的路徑及文件名 --> <file>${LOG_PATH}/log_warn.log</file> <!--日誌文件輸出格式--> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> <charset>UTF-8</charset> <!-- 此處設置字符集 --> </encoder> <!-- 日誌記錄器的滾動策略,按日期,按大小記錄 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 歸檔的日誌文件的路徑,例現在天是2017-04-26日誌,當前寫的日誌文件路徑爲file節點指定,能夠將此文件與file指定文件路徑設置爲不一樣路徑,從而將當前日誌文件或歸檔日誌文件置不一樣的目錄。 而2017-04-26的日誌文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${LOG_PATH}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!-- 除按日誌記錄以外,還配置了日誌文件不能超過500M,若超過500M,日誌文件會以索引0開始, 命名日誌文件,例如log-error-2017-04-26.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <!--日誌文件保留天數--> <maxHistory>30</maxHistory> </rollingPolicy> <!-- 此日誌文件只記錄warn級別的 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>warn</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- 時間滾動輸出 level爲 ERROR 日誌 --> <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 正在記錄的日誌文件的路徑及文件名 --> <file>${LOG_PATH}/log_error.log</file> <!--日誌文件輸出格式--> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> <charset>UTF-8</charset> <!-- 此處設置字符集 --> </encoder> <!-- 日誌記錄器的滾動策略,按日期,按大小記錄 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 歸檔的日誌文件的路徑,例現在天是2017-04-26日誌,當前寫的日誌文件路徑爲file節點指定,能夠將此文件與file指定文件路徑設置爲不一樣路徑,從而將當前日誌文件或歸檔日誌文件置不一樣的目錄。 而2017-04-26的日誌文件在由fileNamePattern指定。%d{yyyy-MM-dd}指定日期格式,%i指定索引 --> <fileNamePattern>${LOG_PATH}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern> <!-- 除按日誌記錄以外,還配置了日誌文件不能超過500M,若超過500M,日誌文件會以索引0開始, 命名日誌文件,例如log-error-2017-04-26.0.log --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <!--日誌文件保留天數--> <maxHistory>30</maxHistory> </rollingPolicy> <!-- 此日誌文件只記錄ERROR級別的 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>error</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <logger name="org.springframework.web" level="info"/> <logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/> <logger name="cn.zhangbox.cloud" level="debug"/> <!--開發環境:打印控制檯--> <springProfile name="dev"> <root level="info"> <appender-ref ref="CONSOLE" /> <appender-ref ref="DEBUG_FILE" /> <appender-ref ref="INFO_FILE" /> <appender-ref ref="WARN_FILE" /> <appender-ref ref="ERROR_FILE" /> </root> </springProfile> <!--測試環境:打印控制檯和輸出到文件--> <springProfile name="test"> <root level="info"> <appender-ref ref="CONSOLE" /> <appender-ref ref="INFO_FILE" /> <appender-ref ref="WARN_FILE" /> <appender-ref ref="ERROR_FILE" /> </root> </springProfile> <!--生產環境:輸出到文件--> <springProfile name="prod"> <root level="error"> <appender-ref ref="CONSOLE" /> <appender-ref ref="DEBUG_FILE" /> <appender-ref ref="INFO_FILE" /> <appender-ref ref="ERROR_FILE" /> </root> </springProfile> </configuration>
在工程java
代碼目錄下建立controller
的目錄在下面建立DcController
類用來測試服務是否已經註冊到eureka
並加入如下代碼:spring
@RestController public class DcController { @Autowired DiscoveryClient discoveryClient; @GetMapping("/dc") public String dc() { String services = "Services: " + discoveryClient.getServices(); System.out.println(services); return services; } }
@EnableDiscoveryClient //使用該註解將註冊服務到eureka @SpringBootApplication public class SpringCloudDemoApplication { public static void main(String[] args) { new SpringApplicationBuilder( SpringCloudDemoApplication.class).web(true).run(args); } }
"C:\Program Files\Java\jdk1.8.0_151\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:51282,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=51281 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_151\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\rt.jar;C:\Users\Administrator\Desktop\manage\spring-cloud-study\cloud-demo\target\classes;D:\開發工具\repository\org\springframework\cloud\spring-cloud-starter-eureka\1.3.1.RELEASE\spring-cloud-starter-eureka-1.3.1.RELEASE.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-starter\1.2.2.RELEASE\spring-cloud-starter-1.2.2.RELEASE.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-context\1.2.2.RELEASE\spring-cloud-context-1.2.2.RELEASE.jar;D:\開發工具\repository\org\springframework\security\spring-security-crypto\4.2.2.RELEASE\spring-security-crypto-4.2.2.RELEASE.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-commons\1.2.2.RELEASE\spring-cloud-commons-1.2.2.RELEASE.jar;D:\開發工具\repository\org\springframework\security\spring-security-rsa\1.0.3.RELEASE\spring-security-rsa-1.0.3.RELEASE.jar;D:\開發工具\repository\org\bouncycastle\bcpkix-jdk15on\1.55\bcpkix-jdk15on-1.55.jar;D:\開發工具\repository\org\bouncycastle\bcprov-jdk15on\1.55\bcprov-jdk15on-1.55.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-netflix-core\1.3.1.RELEASE\spring-cloud-netflix-core-1.3.1.RELEASE.jar;D:\開發工具\repository\org\springframework\boot\spring-boot\1.5.3.RELEASE\spring-boot-1.5.3.RELEASE.jar;D:\開發工具\repository\org\springframework\boot\spring-boot-autoconfigure\1.5.3.RELEASE\spring-boot-autoconfigure-1.5.3.RELEASE.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-netflix-eureka-client\1.3.1.RELEASE\spring-cloud-netflix-eureka-client-1.3.1.RELEASE.jar;D:\開發工具\repository\com\netflix\eureka\eureka-client\1.6.2\eureka-client-1.6.2.jar;D:\開發工具\repository\org\codehaus\jettison\jettison\1.3.7\jettison-1.3.7.jar;D:\開發工具\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar;D:\開發工具\repository\com\netflix\netflix-commons\netflix-eventbus\0.3.0\netflix-eventbus-0.3.0.jar;D:\開發工具\repository\com\netflix\netflix-commons\netflix-infix\0.3.0\netflix-infix-0.3.0.jar;D:\開發工具\repository\commons-jxpath\commons-jxpath\1.3\commons-jxpath-1.3.jar;D:\開發工具\repository\joda-time\joda-time\2.9.9\joda-time-2.9.9.jar;D:\開發工具\repository\org\antlr\antlr-runtime\3.4\antlr-runtime-3.4.jar;D:\開發工具\repository\org\antlr\stringtemplate\3.2.1\stringtemplate-3.2.1.jar;D:\開發工具\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;D:\開發工具\repository\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar;D:\開發工具\repository\org\apache\commons\commons-math\2.2\commons-math-2.2.jar;D:\開發工具\repository\com\netflix\archaius\archaius-core\0.7.4\archaius-core-0.7.4.jar;D:\開發工具\repository\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\開發工具\repository\com\netflix\servo\servo-core\0.10.1\servo-core-0.10.1.jar;D:\開發工具\repository\com\netflix\servo\servo-internal\0.10.1\servo-internal-0.10.1.jar;D:\開發工具\repository\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\開發工具\repository\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\開發工具\repository\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\開發工具\repository\org\apache\httpcomponents\httpclient\4.5.3\httpclient-4.5.3.jar;D:\開發工具\repository\org\apache\httpcomponents\httpcore\4.4.6\httpcore-4.4.6.jar;D:\開發工具\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;D:\開發工具\repository\com\google\inject\guice\4.1.0\guice-4.1.0.jar;D:\開發工具\repository\javax\inject\javax.inject\1\javax.inject-1.jar;D:\開發工具\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\開發工具\repository\com\fasterxml\jackson\core\jackson-annotations\2.8.0\jackson-annotations-2.8.0.jar;D:\開發工具\repository\com\fasterxml\jackson\core\jackson-core\2.8.8\jackson-core-2.8.8.jar;D:\開發工具\repository\com\netflix\eureka\eureka-core\1.6.2\eureka-core-1.6.2.jar;D:\開發工具\repository\org\codehaus\woodstox\woodstox-core-asl\4.4.1\woodstox-core-asl-4.4.1.jar;D:\開發工具\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;D:\開發工具\repository\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-starter-archaius\1.3.1.RELEASE\spring-cloud-starter-archaius-1.3.1.RELEASE.jar;D:\開發工具\repository\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\開發工具\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\開發工具\repository\com\google\guava\guava\18.0\guava-18.0.jar;D:\開發工具\repository\org\springframework\cloud\spring-cloud-starter-ribbon\1.3.1.RELEASE\spring-cloud-starter-ribbon-1.3.1.RELEASE.jar;D:\開發工具\repository\com\netflix\ribbon\ribbon\2.2.2\ribbon-2.2.2.jar;D:\開發工具\repository\com\netflix\ribbon\ribbon-transport\2.2.2\ribbon-transport-2.2.2.jar;D:\開發工具\repository\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\開發工具\repository\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\開發工具\repository\com\netflix\hystrix\hystrix-core\1.5.12\hystrix-core-1.5.12.jar;D:\開發工具\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\開發工具\repository\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\開發工具\repository\io\netty\netty-codec-http\4.0.27.Final\netty-codec-http-4.0.27.Final.jar;D:\開發工具\repository\io\netty\netty-codec\4.0.27.Final\netty-codec-4.0.27.Final.jar;D:\開發工具\repository\io\netty\netty-handler\4.0.27.Final\netty-handler-4.0.27.Final.jar;D:\開發工具\repository\io\netty\netty-transport-native-epoll\4.0.27.Final\netty-transport-native-epoll-4.0.27.Final.jar;D:\開發工具\repository\io\netty\netty-common\4.0.27.Final\netty-common-4.0.27.Final.jar;D:\開發工具\repository\io\netty\netty-buffer\4.0.27.Final\netty-buffer-4.0.27.Final.jar;D:\開發工具\repository\io\netty\netty-transport\4.0.27.Final\netty-transport-4.0.27.Final.jar;D:\開發工具\repository\com\netflix\ribbon\ribbon-core\2.2.2\ribbon-core-2.2.2.jar;D:\開發工具\repository\com\netflix\ribbon\ribbon-httpclient\2.2.2\ribbon-httpclient-2.2.2.jar;D:\開發工具\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\開發工具\repository\com\netflix\netflix-commons\netflix-commons-util\0.1.1\netflix-commons-util-0.1.1.jar;D:\開發工具\repository\com\netflix\ribbon\ribbon-loadbalancer\2.2.2\ribbon-loadbalancer-2.2.2.jar;D:\開發工具\repository\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\開發工具\repository\io\reactivex\rxjava\1.1.10\rxjava-1.1.10.jar;D:\開發工具\repository\com\netflix\ribbon\ribbon-eureka\2.2.2\ribbon-eureka-2.2.2.jar;D:\開發工具\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\開發工具\repository\com\thoughtworks\xstream\xstream\1.4.9\xstream-1.4.9.jar;D:\開發工具\repository\xmlpull\xmlpull\1.1.3.1\xmlpull-1.1.3.1.jar;D:\開發工具\repository\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar;D:\開發工具\repository\org\springframework\boot\spring-boot-starter-web\1.5.3.RELEASE\spring-boot-starter-web-1.5.3.RELEASE.jar;D:\開發工具\repository\org\springframework\boot\spring-boot-starter\1.5.3.RELEASE\spring-boot-starter-1.5.3.RELEASE.jar;D:\開發工具\repository\org\springframework\boot\spring-boot-starter-logging\1.5.3.RELEASE\spring-boot-starter-logging-1.5.3.RELEASE.jar;D:\開發工具\repository\ch\qos\logback\logback-classic\1.1.11\logback-classic-1.1.11.jar;D:\開發工具\repository\ch\qos\logback\logback-core\1.1.11\logback-core-1.1.11.jar;D:\開發工具\repository\org\slf4j\jcl-over-slf4j\1.7.25\jcl-over-slf4j-1.7.25.jar;D:\開發工具\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\開發工具\repository\org\slf4j\log4j-over-slf4j\1.7.25\log4j-over-slf4j-1.7.25.jar;D:\開發工具\repository\org\springframework\spring-core\4.3.8.RELEASE\spring-core-4.3.8.RELEASE.jar;D:\開發工具\repository\org\yaml\snakeyaml\1.17\snakeyaml-1.17.jar;D:\開發工具\repository\org\springframework\boot\spring-boot-starter-tomcat\1.5.3.RELEASE\spring-boot-starter-tomcat-1.5.3.RELEASE.jar;D:\開發工具\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.14\tomcat-embed-core-8.5.14.jar;D:\開發工具\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.14\tomcat-embed-el-8.5.14.jar;D:\開發工具\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.14\tomcat-embed-websocket-8.5.14.jar;D:\開發工具\repository\org\hibernate\hibernate-validator\5.3.5.Final\hibernate-validator-5.3.5.Final.jar;D:\開發工具\repository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;D:\開發工具\repository\org\jboss\logging\jboss-logging\3.3.1.Final\jboss-logging-3.3.1.Final.jar;D:\開發工具\repository\com\fasterxml\classmate\1.3.3\classmate-1.3.3.jar;D:\開發工具\repository\com\fasterxml\jackson\core\jackson-databind\2.8.8\jackson-databind-2.8.8.jar;D:\開發工具\repository\org\springframework\spring-web\4.3.8.RELEASE\spring-web-4.3.8.RELEASE.jar;D:\開發工具\repository\org\springframework\spring-aop\4.3.8.RELEASE\spring-aop-4.3.8.RELEASE.jar;D:\開發工具\repository\org\springframework\spring-beans\4.3.8.RELEASE\spring-beans-4.3.8.RELEASE.jar;D:\開發工具\repository\org\springframework\spring-context\4.3.8.RELEASE\spring-context-4.3.8.RELEASE.jar;D:\開發工具\repository\org\springframework\spring-webmvc\4.3.8.RELEASE\spring-webmvc-4.3.8.RELEASE.jar;D:\開發工具\repository\org\springframework\spring-expression\4.3.8.RELEASE\spring-expression-4.3.8.RELEASE.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.6\lib\idea_rt.jar" cn.zhangbox.cloud.SpringCloudDemoApplication Connected to the target VM, address: '127.0.0.1:51282', transport: 'socket' 2018-07-13 17:13:30.459 INFO 8104 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4416d64f: startup date [Fri Jul 13 17:13:30 GMT+08:00 2018]; root of context hierarchy 2018-07-13 17:13:30.983 INFO 8104 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2018-07-13 17:13:31.057 INFO 8104 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$52bfc5ff] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.5.3.RELEASE) 2018-07-13 17:13:31.835 INFO 8104 --- [ main] c.z.cloud.SpringCloudDemoApplication : The following profiles are active: dev 2018-07-13 17:13:31.850 INFO 8104 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@160396db: startup date [Fri Jul 13 17:13:31 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4416d64f 2018-07-13 17:13:32.470 INFO 8104 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=61cde5fe-b448-3350-a5e4-3ab1b78398ff 2018-07-13 17:13:32.489 INFO 8104 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 2018-07-13 17:13:32.553 INFO 8104 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$52bfc5ff] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2018-07-13 17:13:33.018 INFO 8104 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8081 (http) 2018-07-13 17:13:33.032 INFO 8104 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2018-07-13 17:13:33.034 INFO 8104 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14 2018-07-13 17:13:33.199 INFO 8104 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2018-07-13 17:13:33.199 INFO 8104 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1349 ms 2018-07-13 17:13:33.345 INFO 8104 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2018-07-13 17:13:33.350 INFO 8104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-07-13 17:13:33.351 INFO 8104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-07-13 17:13:33.351 INFO 8104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-07-13 17:13:33.351 INFO 8104 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-07-13 17:13:34.025 INFO 8104 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@160396db: startup date [Fri Jul 13 17:13:31 GMT+08:00 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@4416d64f 2018-07-13 17:13:34.094 INFO 8104 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/dc],methods=[GET]}" onto public java.lang.String cn.zhangbox.cloud.controller.DcController.dc() 2018-07-13 17:13:34.098 INFO 8104 --- [ 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-13 17:13:34.099 INFO 8104 --- [ 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-13 17:13:34.142 INFO 8104 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-13 17:13:34.142 INFO 8104 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2018-07-13 17:13:34.189 INFO 8104 --- [ 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-13 17:13:34.555 WARN 8104 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-13 17:13:34.555 INFO 8104 --- [ 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-13 17:13:34.561 WARN 8104 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources. 2018-07-13 17:13:34.561 INFO 8104 --- [ 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-13 17:13:34.697 INFO 8104 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-07-13 17:13:34.707 INFO 8104 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'environmentManager' has been autodetected for JMX exposure 2018-07-13 17:13:34.708 INFO 8104 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure 2018-07-13 17:13:34.709 INFO 8104 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'refreshScope' has been autodetected for JMX exposure 2018-07-13 17:13:34.711 INFO 8104 --- [ 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-13 17:13:34.726 INFO 8104 --- [ 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-13 17:13:34.739 INFO 8104 --- [ 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=160396db,type=ConfigurationPropertiesRebinder] 2018-07-13 17:13:34.881 INFO 8104 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0 2018-07-13 17:13:34.890 INFO 8104 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING 2018-07-13 17:13:35.012 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1 2018-07-13 17:13:35.418 INFO 8104 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson 2018-07-13 17:13:35.418 INFO 8104 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson 2018-07-13 17:13:35.554 INFO 8104 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml 2018-07-13 17:13:35.554 INFO 8104 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml 2018-07-13 17:13:35.935 INFO 8104 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration 2018-07-13 17:13:36.021 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false 2018-07-13 17:13:36.022 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null 2018-07-13 17:13:36.022 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false 2018-07-13 17:13:36.022 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false 2018-07-13 17:13:36.022 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true 2018-07-13 17:13:36.023 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true 2018-07-13 17:13:36.023 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server 2018-07-13 17:13:36.260 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200 2018-07-13 17:13:36.262 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30 2018-07-13 17:13:36.266 INFO 8104 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4 2018-07-13 17:13:36.269 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1531473216269 with initial instances count: 26 2018-07-13 17:13:36.288 INFO 8104 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application cloud-demo with eureka with status UP 2018-07-13 17:13:36.289 INFO 8104 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1531473216289, current=UP, previous=STARTING] 2018-07-13 17:13:36.291 INFO 8104 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CLOUD-DEMO/windows10.microdone.cn:cloud-demo:8081: registering service... 2018-07-13 17:13:36.342 INFO 8104 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CLOUD-DEMO/windows10.microdone.cn:cloud-demo:8081 - registration status: 204 2018-07-13 17:13:36.360 INFO 8104 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http) 2018-07-13 17:13:36.360 INFO 8104 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8081 2018-07-13 17:13:36.364 INFO 8104 --- [ main] c.z.cloud.SpringCloudDemoApplication : Started SpringCloudDemoApplication in 6.85 seconds (JVM running for 8.116) 2018-07-13 17:13:45.808 INFO 8104 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2018-07-13 17:13:45.809 INFO 8104 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2018-07-13 17:13:45.838 INFO 8104 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 29 ms Services: [zcs-apps-gateway, mystore-user-jwt, eureka-feign-client, scca-server-all-in-one, oms-system, zcs-apps-config, apollo-adminservice, staryun-product, tm-web, gateway-server, config-server, apollo-configservice, base-service, hd-cloud-boss, wm-svr-gateway, tm-admin, gzepro-manage-service, cva, zcs-jzsy-ops-new, x-cbiz, hd-config-server, wm-app-basicmanager, cloud-demo, wm-app-authserver, service-configuration, api-gateway]
瀏覽器輸入地址:
http://eureka.didispace.com/
看到服務已經成功註冊。sql
固然,咱們也能夠經過直接訪問eureka-client
服務提供的/dc
接口來獲取當前的服務清單,只須要訪問:http://localhost:2001/dc,咱們能夠獲得以下輸出返回:
Services: [zcs-apps-gateway, mystore-user-jwt, eureka-feign-client, scca-server-all-in-one, oms-system, zcs-apps-config, apollo-adminservice, staryun-product, tm-web, gateway-server, config-server, apollo-configservice, base-service, hd-cloud-boss, wm-svr-gateway, tm-admin, gzepro-manage-service, cva, zcs-jzsy-ops-new, x-cbiz, hd-config-server, wm-app-basicmanager, cloud-demo, wm-app-authserver, service-configuration, api-gateway]
能夠看到cloud-demo
包含在裏面。至此maven
快速構建cloud
項目並啓動測試已所有完成。
SpringCloud使用Intellij中的maven來快速構建Spring Cloud工程
歡迎關注個人微信公衆號獲取更多更全的學習資源,視頻資料,技術乾貨!