├── .gitignore ├── README.md ├── SUMMARY.md ├── config └── micro-weather-config-client-dev.properties ├── docs ├── api-gateway │ ├── api-gateway-in-action.md │ ├── api-gateway-meaning.md │ ├── api-gateway-patterns.md │ ├── api-gateway.md │ └── zuul.md ├── auto-scale │ ├── auto-scale-in-action.md │ ├── auto-scale-meaning.md │ ├── auto-scale-patterns.md │ ├── auto-scale.md │ └── what.md ├── centralized-configuration │ ├── centralized-configuration.md │ ├── config-in-action.md │ ├── config.md │ ├── principle.md │ └── why.md ├── circuit-breaker │ ├── circuit-breaker-and-service-downgrade.md │ ├── circuit-breaker-meaning.md │ ├── circuit-breaker.md │ ├── hystrix-in-action.md │ ├── hystrix.md │ └── what.md ├── comsumer │ ├── comsumer-cases.md │ ├── comsumer-in-action.md │ ├── comsumer-patterns.md │ ├── comsumer.md │ └── ribbon-in-action.md ├── deploy-publish │ ├── container-deploy-publish.md │ ├── deploy-publish-msa.md │ ├── deploy-publish.md │ ├── docker-deploy.md │ ├── docker-hub.md │ ├── docker-image.md │ ├── docker.md │ └── problems.md ├── msa-boot │ ├── first-api.md │ ├── msa-boot-api.md │ ├── msa-boot-overview.md │ ├── msa-boot-redis.md │ ├── msa-boot-store.md │ └── msa-boot.md ├── references.md ├── register-discover │ ├── discover-meaning.md │ ├── eureka-in-action.md │ ├── eureka.md │ └── register-discover.md └── spring-cloud │ ├── spring-cloud-and-boot.md │ ├── spring-cloud-config.md │ ├── spring-cloud-overview.md │ ├── spring-cloud-projects.md │ └── spring-cloud.md ├── images ├── api-gateway │ └── api-gateway-eureka.jpg ├── centralized-configuration │ ├── config-github.jpg │ └── micro-weather-config-client.jpg ├── comsumer │ └── comsumer-eureka.jpg ├── msa-boot │ └── weather-data.jpg ├── register-discover │ ├── eurake-client.jpg │ ├── eurake-start.jpg │ └── eurake-ui.jpg ├── spring-cloud-logo.png └── spring-cloud │ └── start.jpg └── samples ├── basic-gradle ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ └── Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ └── ApplicationTests.java ├── basic-maven ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ └── Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ └── ApplicationTests.java ├── micro-weather-basic ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ ├── Application.java │ │ │ ├── config │ │ │ └── RestConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherController.java │ │ │ ├── service │ │ │ ├── WeatherDataService.java │ │ │ └── WeatherDataServiceImpl.java │ │ │ └── vo │ │ │ ├── Forecast.java │ │ │ ├── Weather.java │ │ │ ├── WeatherResponse.java │ │ │ └── Yesterday.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ ├── ApplicationTests.java │ └── service │ └── WeatherDataServiceTests.java ├── micro-weather-config-client ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ └── Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ └── ApplicationTests.java ├── micro-weather-config-server ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ └── Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ └── ApplicationTests.java ├── micro-weather-eureka-client ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ └── Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ └── ApplicationTests.java ├── micro-weather-eureka-server ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ └── Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ └── ApplicationTests.java ├── micro-weather-feign ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ ├── Application.java │ │ │ └── service │ │ │ └── HelloClient.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ ├── ApplicationTests.java │ └── service │ └── HelloClientTest.java ├── micro-weather-redis ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── waylau │ │ │ └── spring │ │ │ └── cloud │ │ │ ├── Application.java │ │ │ ├── config │ │ │ └── RestConfiguration.java │ │ │ ├── controller │ │ │ └── WeatherController.java │ │ │ ├── service │ │ │ ├── WeatherDataService.java │ │ │ └── WeatherDataServiceImpl.java │ │ │ └── vo │ │ │ ├── Forecast.java │ │ │ ├── Weather.java │ │ │ ├── WeatherResponse.java │ │ │ └── Yesterday.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── waylau │ └── spring │ └── cloud │ ├── ApplicationTests.java │ └── service │ └── WeatherDataServiceTests.java └── micro-weather-zuul ├── .gitignore ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main ├── java │ └── com │ │ └── waylau │ │ └── spring │ │ └── cloud │ │ └── Application.java └── resources │ └── application.properties └── test └── java └── com └── waylau └── spring └── cloud └── ApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | /.settings/ 3 | *.project 4 | *.classpath 5 | /bin/ 6 | /.idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud Tutorial 《Spring Cloud 教程》 2 | 3 | ![](images/spring-cloud-logo.png) 4 | 5 | Spring Cloud Tutorial takes you to learn Spring Cloud step by step with a large number of samples. There is also a GitBook version of the book: . 6 | Let's [READ](SUMMARY.md)! 7 | 8 | Spring Cloud Tutorial 是一本关于 Spring Cloud 学习的开源书。利用业余时间写了本书,图文并茂,用大量实例带你一步一步走进 Spring Cloud 的世界。如有疏漏欢迎指正,欢迎提问。感谢您的参与! 9 | 10 | **注**:Spring Cloud 基于 Spring Boot 来进行构建服务。有关 Spring Boot 的内容,可以参阅笔者所著的《Spring Boot 教程》() 11 | 12 | ## 涉及技术 13 | 14 | 本书涉及的相关技术及版本如下。 15 | 16 | * Gradle 4.0 17 | * Spring Boot 2.0.0.M3 18 | * Spring Boot Data Redis Starter 2.0.0.M3 19 | * Apache HttpClient 4.5.3 20 | * Redis 3.2.100 21 | * Spring Cloud Netflix Eureka Server Finchley.M2 22 | * Spring Cloud Netflix Eureka Client Finchley.M2 23 | * Spring Cloud Starter OpenFeign Finchley.M2 24 | * Spring Cloud Config Server Finchley.M2 25 | * Spring Cloud Config Client Finchley.M2 26 | 27 | ## Get Started 如何开始阅读 28 | 29 | 选择下面入口之一: 30 | 31 | * 的 [SUMMARY.md](SUMMARY.md)(源码) 32 | * 点击 Read 按钮(同步更新,国内访问速度一般) 33 | * 的 [SUMMARY.md](SUMMARY.md)(码云,手动同步,有所延时) 34 | 35 | ## Code 源码 36 | 37 | 书中所有示例源码,移步至 `samples` 目录下 38 | 39 | ## Issue 意见、建议 40 | 41 | 如有勘误、意见或建议欢迎拍砖 42 | 43 | ## 联系作者: 44 | 45 | 您也可以直接联系我: 46 | 47 | * 博客:https://waylau.com 48 | * 邮箱:[waylau521(at)gmail.com](mailto:waylau521@gmail.com) 49 | * 微博:http://weibo.com/waylau521 50 | * 开源:https://github.com/waylau 51 | 52 | ## 相关资料 53 | 54 | 其他与 Spring Cloud 相关的学习资料还有: 55 | 56 | * 基于Spring Boot的博客系统实战(视频): 57 | * Spring Boot 教程: 58 | * 基于Spring Cloud的微服务实战(视频): 59 | * Spring Boot 企业级应用开发实战(书籍): 60 | * Spring Cloud 微服务架构开发实战(书籍): 61 | 62 | ## 其他书籍 63 | 64 | 若您对本书不感冒,笔者还写了其他方面的超过一打的书籍(可见),多是开源电子书。 65 | 66 | 本人也维护了一个[books-collection](https://github.com/waylau/books-collection)项目,里面提供了优质的专门给程序员的开源、免费图书集合。 67 | 68 | ## 开源捐赠 69 | 70 | 71 | ![开源捐赠](https://waylau.com/images/showmethemoney-sm.jpg) 72 | 73 | 捐赠所得所有款项将用于开源事业! -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [Spring Cloud 介绍](docs/spring-cloud/spring-cloud.md) 4 | * [Spring Cloud 简介](docs/spring-cloud/spring-cloud-overview.md)(完) 5 | * [Spring Cloud 入门配置](docs/spring-cloud/spring-cloud-config.md)(完) 6 | * [Spring Cloud 的子项目介绍](docs/spring-cloud/spring-cloud-projects.md)(完) 7 | * [Spring Cloud 与 Spring Boot 的关系](docs/spring-cloud/spring-cloud-and-boot.md)(完) 8 | * [微服务 与 Spring Boot](docs/msa-boot/msa-boot.md) 9 | * [微服务架构概述](docs/msa-boot/msa-boot-overview.md) 10 | * [微服务 API 设计原则](docs/msa-boot/msa-boot-api.md) 11 | * [微服务存储设计原则](docs/msa-boot/msa-boot-store.md) 12 | * [第一个微服务实现——天气预报服务](https://waylau.com/spring-boot-weather-report/) (完) 13 | * [提升微服务的并发访问能力](docs/msa-boot/msa-boot-redis.md) (完) 14 | * [微服务的注册与发现](docs/register-discover/register-discover.md) 15 | * [服务发现的意义](docs/register-discover/discover-meaning.md) 16 | * [如何集成Eureka](docs/register-discover/eureka.md)(完) 17 | * [实现服务的注册与发现](docs/register-discover/eureka-in-action.md)(完) 18 | * [微服务的消费](docs/comsumer/comsumer.md) 19 | * [微服务的消费模式](docs/comsumer/comsumer-patterns.md) 20 | * [常见微服务的消费者](docs/comsumer/comsumer-cases.md) 21 | * [实现服务的消费者](docs/comsumer/comsumer-in-action.md)(完) 22 | * [实现服务的负载均衡及高可用](docs/comsumer/ribbon-in-action.md)(完) 23 | * [API 网关](docs/api-gateway/api-gateway.md) 24 | * [API 网关的意义](docs/api-gateway/api-gateway-meaning.md) 25 | * [常见 API 网关的实现方式](docs/api-gateway/api-gateway-patterns.md) 26 | * [如何集成Zuul](docs/api-gateway/zuul.md)(完) 27 | * [实现 API 网关](docs/api-gateway/api-gateway-in-action.md)(完) 28 | * [微服务的部署与发布](docs/deploy-publish/deploy-publish.md) 29 | * [部署微服务将面临的挑战](docs/deploy-publish/problems.md) 30 | * [持续交付与持续部署微服务](docs/deploy-publish/deploy-publish-msa.md) 31 | * [基于容器的部署与发布微服务](docs/deploy-publish/container-deploy-publish.md) 32 | * [Docker 简介](docs/deploy-publish/docker.md) 33 | * [基于 Docker 打包](docs/deploy-publish/docker-image.md) 34 | * [基于 Docker 发布](docs/deploy-publish/docker-hub.md) 35 | * [基于 Docker 部署](docs/deploy-publish/docker-deploy.md) 36 | * [微服务的集中化配置](docs/centralized-configuration/centralized-configuration.md) 37 | * [为什么需要集中化配置](docs/centralized-configuration/why.md) 38 | * [集中化配置的实现原理](docs/centralized-configuration/principle.md) 39 | * [如何集成 Spring Cloud Config](docs/centralized-configuration/config.md)(完) 40 | * [实现微服务的集中化配置](docs/centralized-configuration/config-in-action.md)(完) 41 | * [微服务的高级主题——自动扩展](docs/auto-scale/auto-scale.md) 42 | * [什么是自动扩展](docs/auto-scale/what.md) 43 | * [自动扩展的意义](docs/auto-scale/auto-scale-meaning.md) 44 | * [自动扩展的常见模式](docs/auto-scale/auto-scale-patterns.md) 45 | * [实现微服务的自动扩展](docs/auto-scale/auto-scale-in-action.md) 46 | * [微服务的高级主题——熔断机制](docs/circuit-breaker/circuit-breaker.md) 47 | * [什么是服务的熔断机制](docs/circuit-breaker/what.md) 48 | * [熔断的意义](docs/circuit-breaker/circuit-breaker-meaning.md) 49 | * [熔断与降级的区别](docs/circuit-breaker/circuit-breaker-and-service-downgrade.md) 50 | * [如何集成 Hystrix](docs/circuit-breaker/hystrix.md) 51 | * [实现微服务的熔断机制](docs/circuit-breaker/hystrix-in-action.md) 52 | * [参考资料](docs/references.md) 53 | 54 | -------------------------------------------------------------------------------- /config/micro-weather-config-client-dev.properties: -------------------------------------------------------------------------------- 1 | auther=waylau.com -------------------------------------------------------------------------------- /docs/api-gateway/api-gateway-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现 API 网关 2 | 3 | ## 一个最简单的 Zuul 应用 4 | 5 | 主应用: 6 | 7 | ```java 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableZuulProxy 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | } 18 | ``` 19 | 20 | 其中:`@EnableZuulProxy`启用了 Zuul 作为反向代理服务器。 21 | 22 | 项目配置: 23 | 24 | ``` 25 | spring.application.name: micro-weather-zuul 26 | 27 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 28 | 29 | zuul.routes.users.path: /hi/** 30 | zuul.routes.users.serviceId: micro-weather-eureka-client 31 | ``` 32 | 33 | 其中: 34 | 35 | * zuul.routes.users.path : 为要拦截请求的路径; 36 | * zuul.routes.users.serviceId:为要拦截请求的路径所要映射的服务。本例,我们将所有`/hi`下的请求,都转发到 `micro-weather-eureka-client` 服务中去。 37 | 38 | ## 如何测试 39 | 40 | 启动在之前章节中搭建的 `micro-weather-eureka-server` 和 `micro-weather-eureka-client` 两个项目,以及本例的 `micro-weather-zuul` 。 41 | 42 | 43 | 如果一切正常,在之前章节中搭建的 `micro-weather-eureka-server` 管理界面,能看到上述服务的信息。 44 | 45 | ![api-gateway-eurekn](../../images/api-gateway/api-gateway-eureka.jpg) 46 | 47 | 48 | 在浏览器访问 `micro-weather-zuul`服务(本例,地址为),当我们试图访问接口时,只需要访问如果一切正常,可以在控制台看到“Hello world”字样,这个就是转发请求到`micro-weather-eureka-client` 服务时响应的内容。 49 | 50 | 51 | 52 | ## 源码 53 | 54 | 本章节源码,见`micro-weather-zuul` 。 -------------------------------------------------------------------------------- /docs/api-gateway/api-gateway-meaning.md: -------------------------------------------------------------------------------- 1 | # API 网关的意义 2 | 3 | -------------------------------------------------------------------------------- /docs/api-gateway/api-gateway-patterns.md: -------------------------------------------------------------------------------- 1 | # 常见 API 网关的实现方式 2 | 3 | -------------------------------------------------------------------------------- /docs/api-gateway/api-gateway.md: -------------------------------------------------------------------------------- 1 | # API 网关 2 | 3 | -------------------------------------------------------------------------------- /docs/api-gateway/zuul.md: -------------------------------------------------------------------------------- 1 | # 如何集成Zuul 2 | 3 | 路由是微服务架构中必须的一部分,比如,“/” 可能映射到你的WEB程序上,“/api/users”可能映射到你的用户服务上,“/api/shop”可能映射到你的商品服务商。通过路由,让不同的服务,都集中到统一的入口上来,这就是 API 网关的作用。 4 | 5 | Zuul是Netflix出品的一个基于JVM路由和服务端的负载均衡器. 6 | 7 | Zuul功能包括: 8 | 9 | * 认证 10 | * 压力测试 11 | * 金丝雀测试 12 | * 动态路由 13 | * 负载削减 14 | * 安全 15 | * 静态响应处理 16 | * 主动/主动交换管理 17 | 18 | Zuul的规则引擎允许通过任何JVM语言来编写规则和过滤器, 支持基于Java和Groovy的构建。 19 | 20 | 配置属性 zuul.max.host.connections 已经被两个新的配置属性替代, zuul.host.maxTotalConnections (总连接数)和 zuul.host.maxPerRouteConnections,(每个路由连接数) 默认值分别是200和20。 21 | 22 | 23 | 24 | 在 `micro-weather-eureka-client` 的基础上稍作修改即可。新的项目称为`micro-weather-zuul` 。 25 | 26 | ## 开发环境 27 | 28 | * Gradle 4.0 29 | * Spring Boot 2.0.0.M3 30 | * Spring Cloud Netflix Eureka Client Finchley.M2 31 | * Spring Cloud Netflix Zuul Finchley.M2 32 | 33 | ## 更改配置 34 | 35 | 增加如下配置: 36 | 37 | ```groovy 38 | dependencies { 39 | //... 40 | 41 | compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul') 42 | 43 | //... 44 | } 45 | ``` -------------------------------------------------------------------------------- /docs/auto-scale/auto-scale-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现微服务的自动扩展 2 | 3 | -------------------------------------------------------------------------------- /docs/auto-scale/auto-scale-meaning.md: -------------------------------------------------------------------------------- 1 | # 自动扩展的意义 2 | 3 | -------------------------------------------------------------------------------- /docs/auto-scale/auto-scale-patterns.md: -------------------------------------------------------------------------------- 1 | # 自动扩展的常见模式 2 | 3 | -------------------------------------------------------------------------------- /docs/auto-scale/auto-scale.md: -------------------------------------------------------------------------------- 1 | # 微服务的高级主题——自动扩展 2 | 3 | -------------------------------------------------------------------------------- /docs/auto-scale/what.md: -------------------------------------------------------------------------------- 1 | # 什么是自动扩展 2 | 3 | -------------------------------------------------------------------------------- /docs/centralized-configuration/centralized-configuration.md: -------------------------------------------------------------------------------- 1 | # 微服务的集中化配置 2 | 3 | -------------------------------------------------------------------------------- /docs/centralized-configuration/config-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现微服务的集中化配置 2 | 3 | 创建一个`micro-weather-config-client` 作为配置服务器的客户端。 4 | 5 | ## 开发环境 6 | 7 | * Gradle 4.0 8 | * Spring Boot 2.0.0.M3 9 | * Spring Cloud Netflix Eureka Client Finchley.M2 10 | * Spring Cloud Config Client Finchley.M2 11 | 12 | ## 更改配置 13 | 14 | 增加如下配置: 15 | 16 | ```groovy 17 | dependencies { 18 | //... 19 | 20 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 21 | compile('org.springframework.cloud:spring-cloud-starter-config') 22 | 23 | //... 24 | } 25 | ``` 26 | 27 | 项目配置: 28 | 29 | ``` 30 | spring.application.name: micro-weather-config-client 31 | server.port=8089 32 | 33 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 34 | 35 | spring.cloud.config.profile=dev 36 | spring.cloud.config.uri= http://localhost:8888/ 37 | ``` 38 | 39 | 其中: 40 | 41 | * spring.cloud.config.uri : 指向了配置服务器`micro-weather-config-server`的位置。 42 | 43 | ## 一个最简单的 Config Client 44 | 45 | 主应用: 46 | 47 | ```java 48 | @SpringBootApplication 49 | @EnableDiscoveryClient 50 | public class Application { 51 | 52 | public static void main(String[] args) { 53 | SpringApplication.run(Application.class, args); 54 | } 55 | 56 | } 57 | ``` 58 | 59 | ## 如何测试 60 | 61 | 62 | 在 我们放置了一个配置文件`micro-weather-config-client-dev.properties`,里面简单的放置了测试内容: 63 | 64 | ``` 65 | auther=waylau.com 66 | ``` 67 | 68 | ![micro-weather-config-client](../../images/centralized-configuration/config-github.jpg) 69 | 70 | 71 | 编写测试用例: 72 | 73 | ```java 74 | @RunWith(SpringRunner.class) 75 | @SpringBootTest 76 | public class ApplicationTests { 77 | 78 | @Value("${auther}") 79 | private String auther; 80 | 81 | @Test 82 | public void contextLoads() { 83 | System.out.println(auther); 84 | } 85 | 86 | } 87 | ``` 88 | 89 | 启动在之前章节中搭建的 `micro-weather-eureka-server` 和 `micro-weather-config-server` 两个项目。 90 | 91 | 92 | 启动测试用例,如果一切正常,可以在控制台看到“waylau.com”字样,说明,我们拿到了`auther`在配置服务器中的内容。 93 | 94 | 如果同时也启动了 `micro-weather-config-client` 项目,则能在 95 | 启动在之前章节中搭建的 `micro-weather-eureka-server` 管理界面,看到这个服务的信息。 96 | 97 | ![micro-weather-config-client](../../images/centralized-configuration/micro-weather-config-client.jpg) 98 | 99 | ## 源码 100 | 101 | 本章节源码,见`micro-weather-config-client` 。 -------------------------------------------------------------------------------- /docs/centralized-configuration/config.md: -------------------------------------------------------------------------------- 1 | # 如何集成 Config 2 | 3 | 本章节,我们将创建一个`micro-weather-config-server` 作为配置服务器的服务端。 4 | 5 | ## 开发环境 6 | 7 | * Gradle 4.0 8 | * Spring Boot 2.0.0.M3 9 | * Spring Cloud Netflix Eureka Client Finchley.M2 10 | * Spring Cloud Config Server Finchley.M2 11 | 12 | 13 | ## 更改配置 14 | 15 | 增加如下配置: 16 | 17 | ```groovy 18 | dependencies { 19 | //... 20 | 21 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 22 | compile('org.springframework.cloud:spring-cloud-config-server') 23 | 24 | //... 25 | } 26 | ``` 27 | 28 | 项目配置: 29 | 30 | ``` 31 | spring.application.name: micro-weather-config-server 32 | server.port=8888 33 | 34 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 35 | 36 | spring.cloud.config.server.git.uri=https://github.com/waylau/spring-cloud-tutorial 37 | spring.cloud.config.server.git.searchPaths=config 38 | ``` 39 | 40 | 其中: 41 | 42 | * spring.cloud.config.server.git.uri:配置Git仓库地址 43 | * spring.cloud.config.server.git.searchPaths:配置查找配置的路径 44 | 45 | ## 一个最简单的 Config Server 46 | 47 | 主应用: 48 | 49 | ```java 50 | @SpringBootApplication 51 | @EnableDiscoveryClient 52 | @EnableConfigServer 53 | public class Application { 54 | 55 | public static void main(String[] args) { 56 | SpringApplication.run(Application.class, args); 57 | } 58 | 59 | } 60 | ``` 61 | 62 | 在程序的入口Application类加上`@EnableConfigServer`注解开启配置服务器的功能。 63 | 64 | ## 测试 65 | 66 | 在 我们放置了一个配置文件`micro-weather-config-client-dev.properties`,里面简单的放置了测试内容: 67 | 68 | ``` 69 | auther=waylau.com 70 | ``` 71 | 72 | 启动应用,访问,应能看到如下输出内容,说明服务启动正常。 73 | 74 | ```json 75 | {"name":"auther","profiles":["dev"],"label":null,"version":"00836f0fb49488bca170c8227e3ef13a5aff2d1a","state":null,"propertySources":[]} 76 | ``` 77 | 78 | 其中,在配置中心的文件命名规则如下: 79 | 80 | ``` 81 | /{application}/{profile}[/{label}] 82 | /{application}-{profile}.yml 83 | /{label}/{application}-{profile}.yml 84 | /{application}-{profile}.properties 85 | /{label}/{application}-{profile}.properties 86 | ``` 87 | 88 | 89 | ## 源码 90 | 91 | 本章节源码,见`micro-weather-config-server` 。 -------------------------------------------------------------------------------- /docs/centralized-configuration/principle.md: -------------------------------------------------------------------------------- 1 | # 集中化配置的实现原理 2 | 3 | -------------------------------------------------------------------------------- /docs/centralized-configuration/why.md: -------------------------------------------------------------------------------- 1 | # 为什么需要集中化配置 2 | 3 | -------------------------------------------------------------------------------- /docs/circuit-breaker/circuit-breaker-and-service-downgrade.md: -------------------------------------------------------------------------------- 1 | # 熔断与降级的区别 2 | 3 | -------------------------------------------------------------------------------- /docs/circuit-breaker/circuit-breaker-meaning.md: -------------------------------------------------------------------------------- 1 | # 熔断的意义 2 | 3 | -------------------------------------------------------------------------------- /docs/circuit-breaker/circuit-breaker.md: -------------------------------------------------------------------------------- 1 | # 微服务的高级主题——熔断机制 2 | 3 | -------------------------------------------------------------------------------- /docs/circuit-breaker/hystrix-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现微服务的熔断机制 2 | 3 | -------------------------------------------------------------------------------- /docs/circuit-breaker/hystrix.md: -------------------------------------------------------------------------------- 1 | # 如何集成 Hystrix 2 | 3 | -------------------------------------------------------------------------------- /docs/circuit-breaker/what.md: -------------------------------------------------------------------------------- 1 | # 什么是服务的熔断机制 2 | 3 | -------------------------------------------------------------------------------- /docs/comsumer/comsumer-cases.md: -------------------------------------------------------------------------------- 1 | # 常见微服务的消费者 2 | 3 | -------------------------------------------------------------------------------- /docs/comsumer/comsumer-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现服务的消费者 2 | 3 | 本章节,我们将创建一个`micro-weather-feign` 作为服务器的消费者,并演示如何使用 Feign 来消费服务。 4 | 5 | 在 `micro-weather-eureka-client` 的基础上稍作修改即可。 6 | 7 | ## 开发环境 8 | 9 | * Gradle 4.0 10 | * Spring Boot 2.0.0.M3 11 | * Spring Cloud Netflix Eureka Client Finchley.M2 12 | * Spring Cloud Starter OpenFeign Finchley.M2 13 | 14 | ## 更改配置 15 | 16 | 增加如下配置: 17 | 18 | ```groovy 19 | dependencies { 20 | //... 21 | 22 | compile('org.springframework.cloud:spring-cloud-starter-openfeign') 23 | 24 | //... 25 | } 26 | ``` 27 | 28 | ## 声明式 REST 客户端——Feign 29 | 30 | Feign 是一个声明式的 Web 服务客户端。这使得Web服务客户端的写入更加方便。它具有可插拔注释支持,包括Feign注释和JAX-RS注释。Feign还支持可插拔编码器和解码器。Spring Cloud增加了对Spring MVC注释的支持,并且使用了在Spring Web中默认使用的相同的HttpMessageConverter。 在使用Feign时,Spring Cloud集成了Ribbon和Eureka来提供负载平衡的http客户端。 31 | 32 | ## 一个最简单的 Feign 33 | 34 | 主应用: 35 | 36 | ```java 37 | @SpringBootApplication 38 | @EnableDiscoveryClient 39 | @EnableFeignClients 40 | public class Application { 41 | 42 | public static void main(String[] args) { 43 | SpringApplication.run(Application.class, args); 44 | } 45 | 46 | } 47 | ``` 48 | 49 | 编写 Feign 请求接口: 50 | 51 | ```java 52 | package com.waylau.spring.cloud.service; 53 | 54 | import org.springframework.cloud.netflix.feign.FeignClient; 55 | import org.springframework.web.bind.annotation.RequestMapping; 56 | import org.springframework.web.bind.annotation.RequestMethod; 57 | 58 | /** 59 | * Hello Client 60 | * 61 | * @since 1.0.0 2017年9月17日 62 | * @author Way Lau 63 | */ 64 | @FeignClient("micro-weather-eureka-client") 65 | public interface HelloClient { 66 | @RequestMapping(method = RequestMethod.GET, value = "/hello") 67 | String getHello(); 68 | } 69 | ``` 70 | 71 | 其中:`@FeignClient`指定了要访问的服务的名称“micro-weather-eureka-client”。 72 | 73 | 项目配置: 74 | 75 | ``` 76 | spring.application.name: micro-weather-feign 77 | 78 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 79 | 80 | feign.client.config.feignName.connectTimeout: 5000 81 | feign.client.config.feignName.readTimeout: 5000 82 | ``` 83 | 84 | 85 | ## 如何测试 86 | 87 | 编写测试用例: 88 | 89 | ```java 90 | @RunWith(SpringRunner.class) 91 | @SpringBootTest 92 | public class HelloClientTest { 93 | 94 | @Autowired 95 | private HelloClient helloClient; 96 | 97 | @Test 98 | public void testHello() { 99 | String hello = helloClient.getHello(); 100 | System.out.println(hello); 101 | } 102 | 103 | } 104 | ``` 105 | 106 | 启动在之前章节中搭建的 `micro-weather-eureka-server` 和 `micro-weather-eureka-client` 两个项目。这样, `micro-weather-eureka-client`服务,就能被 `micro-weather-feign` 发现,并进行访问。 107 | 108 | 109 | 启动测试用例,如果一切正常,可以在控制台看到“Hello world”字样。这个就是请求`micro-weather-eureka-client` 服务时响应的内容。 110 | 111 | 如果同时也启动了 `micro-weather-feign` 项目,则能在 112 | 启动在之前章节中搭建的 `micro-weather-eureka-server` 管理界面,看到这个服务的信息。 113 | 114 | ![micro-weather-feign](../../images/comsumer/comsumer-eureka.jpg) 115 | 116 | ## 源码 117 | 118 | 本章节源码,见`micro-weather-feign` 。 -------------------------------------------------------------------------------- /docs/comsumer/comsumer-patterns.md: -------------------------------------------------------------------------------- 1 | # 微服务的消费模式 2 | 3 | -------------------------------------------------------------------------------- /docs/comsumer/comsumer.md: -------------------------------------------------------------------------------- 1 | # 微服务的消费 2 | 3 | -------------------------------------------------------------------------------- /docs/comsumer/ribbon-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现服务的负载均衡及高可用 2 | 3 | 如果你自己观察 Feign 依赖,可以看到,Feign 是依赖了 Ribbon的。 4 | 5 | ```xml 6 | 7 | org.springframework.cloud 8 | spring-cloud-starter-netflix-ribbon 9 | 10 | ``` 11 | 12 | 有兴趣的朋友,可以自行查看依赖信息: 13 | 14 | ## 客户端负载均衡器——Ribbon 15 | 16 | Ribbon 是一个客户端负载平衡器,它可以很好地控制HTTP和TCP客户端的行为。 Feign 已经使用 Ribbon,所以如果你使用`@FeignClient`,就已经启用了客户端负载均衡功能。 17 | 18 | Ribbon 的一个中心概念就是命名客户端(named clien)。 每个负载平衡器都是组合的组件的一部分,它们一起工作以根据需要联系远程服务器,并且集合具有您将其作为应用程序开发人员(例如使用`@FeignClient`注解)的名称。 Spring Cloud使用RibbonClientConfiguration为每个命名的客户端根据需要创建一个新的集合作为ApplicationContext。 这包含(其中包括)一个ILoadBalancer,一个RestClient和一个ServerListFilter。 19 | 20 | ## 实现高可用 21 | 22 | 将我们需要访问的服务(比如,“micro-weather-eureka-client”),启动为多个示例。当客户端需要访问“micro-weather-eureka-client”时,会自行去选择其中任意一个服务实例来访问,这样,即便其中的某个服务实例不可用,也不会影响整个服务功能。 23 | 24 | 这样就实现了服务的高可用。 -------------------------------------------------------------------------------- /docs/deploy-publish/container-deploy-publish.md: -------------------------------------------------------------------------------- 1 | # 基于容器的部署与发布微服务 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/deploy-publish-msa.md: -------------------------------------------------------------------------------- 1 | # 持续交付与持续部署微服务 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/deploy-publish.md: -------------------------------------------------------------------------------- 1 | # 微服务的部署与发布 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/docker-deploy.md: -------------------------------------------------------------------------------- 1 | # 基于 Docker 部署 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/docker-hub.md: -------------------------------------------------------------------------------- 1 | # 基于 Docker 发布 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/docker-image.md: -------------------------------------------------------------------------------- 1 | # 基于 Docker 打包 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/docker.md: -------------------------------------------------------------------------------- 1 | # Docker 简介 2 | 3 | -------------------------------------------------------------------------------- /docs/deploy-publish/problems.md: -------------------------------------------------------------------------------- 1 | # 部署微服务将面临的挑战 2 | 3 | -------------------------------------------------------------------------------- /docs/msa-boot/first-api.md: -------------------------------------------------------------------------------- 1 | # 第一个微服务实现——天气预报服务 2 | 3 | 4 | 本章节,我们将基于 Spring Boot 技术来实现我们的第一个微服务天气预报应用——micro-weather-basic。micro-weather-basic 的作用是实现简单的天气预报功能,可以根据不同的城市,查询该城市的实时天气情况。 5 | 6 | ## 开发环境 7 | 8 | * Gradle 4.0 9 | * Spring Boot 1.5.6 10 | * Apache HttpClient 4.5.3 11 | 12 | ## 数据来源 13 | 14 | 理论上,天气的数据是天气预报的实现基础。本应用与实际的天气数据无关,理论上,可以兼容多种数据来源。但为求简单,我们在网上找了一个免费、可用的天气数据接口。 15 | 16 | * 天气数据来源为中华万年历。例如: 17 | * 通过城市名字获得天气数据 : 18 | * 通过城市id获得天气数据: 19 | * 城市ID列表。每个城市都有一个唯一的ID作为标识。见 或者 。 20 | 21 | 调用天气服务接口示例,我们以“深圳”城市为例,可用看到如下天气数据返回。 22 | 23 | ```json 24 | { 25 | "data": { 26 | "yesterday": { 27 | "date": "1日星期五", 28 | "high": "高温 33℃", 29 | "fx": "无持续风向", 30 | "low": "低温 26℃", 31 | "fl": "", 32 | "type": "多云" 33 | }, 34 | "city": "深圳", 35 | "aqi": "72", 36 | "forecast": [ 37 | { 38 | "date": "2日星期六", 39 | "high": "高温 32℃", 40 | "fengli": "", 41 | "low": "低温 26℃", 42 | "fengxiang": "无持续风向", 43 | "type": "阵雨" 44 | }, 45 | { 46 | "date": "3日星期天", 47 | "high": "高温 29℃", 48 | "fengli": "", 49 | "low": "低温 26℃", 50 | "fengxiang": "无持续风向", 51 | "type": "大雨" 52 | }, 53 | { 54 | "date": "4日星期一", 55 | "high": "高温 29℃", 56 | "fengli": "", 57 | "low": "低温 26℃", 58 | "fengxiang": "西南风", 59 | "type": "暴雨" 60 | }, 61 | { 62 | "date": "5日星期二", 63 | "high": "高温 31℃", 64 | "fengli": "", 65 | "low": "低温 27℃", 66 | "fengxiang": "无持续风向", 67 | "type": "阵雨" 68 | }, 69 | { 70 | "date": "6日星期三", 71 | "high": "高温 32℃", 72 | "fengli": "", 73 | "low": "低温 27℃", 74 | "fengxiang": "无持续风向", 75 | "type": "阵雨" 76 | } 77 | ], 78 | "ganmao": "风较大,阴冷潮湿,较易发生感冒,体质较弱的朋友请注意适当防护。", 79 | "wendu": "29" 80 | }, 81 | "status": 1000, 82 | "desc": "OK" 83 | } 84 | ``` 85 | 86 | 我们通过观察数据,来了解每个返回字段的含义。 87 | 88 | * "city": 城市名称 89 | * "aqi": 空气指数, 90 | * "wendu": 实时温度 91 | * "date": 日期,包含未来5天 92 | * "high":最高温度 93 | * "low": 最低温度 94 | * "fengli": 风力 95 | * "fengxiang": 风向 96 | * "type": 天气类型 97 | 98 | 以上数据,是我们需要的天气数据的核心数据,但是,同时也要关注下面两个字段: 99 | 100 | * "status": 接口调用的返回状态,返回值“1000”,意味着数据是接口正常 101 | * "desc": 接口状态的描述,“OK”代表接口正常 102 | 103 | 重点关注返回值不是“1000”的情况,说明,这个接口调用异常了。 104 | 105 | ## 初始化一个 Spring Boot 项目 106 | 107 | 初始化一个 Spring Boot 项目 `micro-weather-basic`,该项目可以直接在我们之前章节课程中的 basic-gradle 项目基础进行修改。同时,为了优化项目的构建速度,我们对Maven中央仓库地址和 Gradle Wrapper 地址做了调整。其中细节暂且不表,读者可以自行参阅源码,或者学习笔者所著的《Spring Boot 教程》()。其原理,我也整理到我的博客中了: 108 | 109 | * https://waylau.com/change-gradle-wrapper-distribution-url-to-local-file/ 110 | * https://waylau.com/use-maven-mirrors/ 111 | 112 | 113 | ## 项目配置 114 | 115 | 添加 Apache HttpClient 的依赖,来作为我们Web请求的客户端。 116 | 117 | ```groovy 118 | // 依赖关系 119 | dependencies { 120 | //... 121 | 122 | // 添加 Apache HttpClient 依赖 123 | compile('org.apache.httpcomponents:httpclient:4.5.3') 124 | 125 | //... 126 | } 127 | ``` 128 | ## 创建天气信息相关的值对象 129 | 130 | 131 | 创建`com.waylau.spring.cloud.vo`包,用于相关值对象。创建天气信息类 Weather 132 | 133 | 134 | ```java 135 | public class Weather implements Serializable { 136 | 137 | private static final long serialVersionUID = 1L; 138 | 139 | private String city; 140 | private String aqi; 141 | private String wendu; 142 | private String ganmao; 143 | private Yesterday yesterday; 144 | private List forecast; 145 | 146 | public String getCity() { 147 | return city; 148 | } 149 | public void setCity(String city) { 150 | this.city = city; 151 | } 152 | public String getAqi() { 153 | return aqi; 154 | } 155 | public void setAqi(String aqi) { 156 | this.aqi = aqi; 157 | } 158 | public String getWendu() { 159 | return wendu; 160 | } 161 | public void setWendu(String wendu) { 162 | this.wendu = wendu; 163 | } 164 | public String getGanmao() { 165 | return ganmao; 166 | } 167 | public void setGanmao(String ganmao) { 168 | this.ganmao = ganmao; 169 | } 170 | public Yesterday getYesterday() { 171 | return yesterday; 172 | } 173 | public void setYesterday(Yesterday yesterday) { 174 | this.yesterday = yesterday; 175 | } 176 | public List getForecast() { 177 | return forecast; 178 | } 179 | public void setForecast(List forecast) { 180 | this.forecast = forecast; 181 | } 182 | } 183 | ``` 184 | 185 | 昨日天气信息: 186 | 187 | ```java 188 | public class Yesterday implements Serializable { 189 | 190 | private static final long serialVersionUID = 1L; 191 | 192 | private String date; 193 | private String high; 194 | private String fx; 195 | private String low; 196 | private String fl; 197 | private String type; 198 | 199 | public Yesterday() { 200 | 201 | } 202 | 203 | public String getDate() { 204 | return date; 205 | } 206 | 207 | public void setDate(String date) { 208 | this.date = date; 209 | } 210 | 211 | public String getHigh() { 212 | return high; 213 | } 214 | 215 | public void setHigh(String high) { 216 | this.high = high; 217 | } 218 | 219 | public String getFx() { 220 | return fx; 221 | } 222 | 223 | public void setFx(String fx) { 224 | this.fx = fx; 225 | } 226 | 227 | public String getLow() { 228 | return low; 229 | } 230 | 231 | public void setLow(String low) { 232 | this.low = low; 233 | } 234 | 235 | public String getFl() { 236 | return fl; 237 | } 238 | 239 | public void setFl(String fl) { 240 | this.fl = fl; 241 | } 242 | 243 | public String getType() { 244 | return type; 245 | } 246 | 247 | public void setType(String type) { 248 | this.type = type; 249 | } 250 | 251 | } 252 | ``` 253 | 254 | 255 | 256 | 未来天气信息: 257 | 258 | ```java 259 | public class Forecast implements Serializable { 260 | 261 | private static final long serialVersionUID = 1L; 262 | 263 | private String date; 264 | private String high; 265 | private String fengxiang; 266 | private String low; 267 | private String fengli; 268 | private String type; 269 | 270 | public String getDate() { 271 | return date; 272 | } 273 | 274 | public void setDate(String date) { 275 | this.date = date; 276 | } 277 | 278 | public String getHigh() { 279 | return high; 280 | } 281 | 282 | public void setHigh(String high) { 283 | this.high = high; 284 | } 285 | 286 | public String getFengxiang() { 287 | return fengxiang; 288 | } 289 | 290 | public void setFengxiang(String fengxiang) { 291 | this.fengxiang = fengxiang; 292 | } 293 | 294 | public String getLow() { 295 | return low; 296 | } 297 | 298 | public void setLow(String low) { 299 | this.low = low; 300 | } 301 | 302 | public String getFengli() { 303 | return fengli; 304 | } 305 | 306 | public void setFengli(String fengli) { 307 | this.fengli = fengli; 308 | } 309 | 310 | public String getType() { 311 | return type; 312 | } 313 | 314 | public void setType(String type) { 315 | this.type = type; 316 | } 317 | 318 | public Forecast() { 319 | 320 | } 321 | 322 | } 323 | ``` 324 | 325 | WeatherResponse 作为整个消息的返回对象 326 | 327 | ```java 328 | public class WeatherResponse implements Serializable { 329 | 330 | private static final long serialVersionUID = 1L; 331 | 332 | private Weather data; // 消息数据 333 | private String status; // 消息状态 334 | private String desc; // 消息描述 335 | 336 | public Weather getData() { 337 | return data; 338 | } 339 | 340 | public void setData(Weather data) { 341 | this.data = data; 342 | } 343 | 344 | public String getStatus() { 345 | return status; 346 | } 347 | 348 | public void setStatus(String status) { 349 | this.status = status; 350 | } 351 | 352 | public String getDesc() { 353 | return desc; 354 | } 355 | 356 | public void setDesc(String desc) { 357 | this.desc = desc; 358 | } 359 | 360 | } 361 | 362 | ``` 363 | 364 | ## 服务接口及实现 365 | 366 | 定义了获取服务的两个接口方法 367 | 368 | ```java 369 | public interface WeatherDataService { 370 | 371 | /** 372 | * 根据城市ID查询天气数据 373 | * @param cityId 374 | * @return 375 | */ 376 | WeatherResponse getDataByCityId(String cityId); 377 | 378 | /** 379 | * 根据城市名称查询天气数据 380 | * @param cityId 381 | * @return 382 | */ 383 | WeatherResponse getDataByCityName(String cityName); 384 | } 385 | ``` 386 | 387 | 其实现为: 388 | 389 | ```java 390 | @Service 391 | public class WeatherDataServiceImpl implements WeatherDataService { 392 | 393 | @Autowired 394 | private RestTemplate restTemplate; 395 | 396 | private final String WEATHER_API = "http://wthrcdn.etouch.cn/weather_mini"; 397 | 398 | @Override 399 | public WeatherResponse getDataByCityId(String cityId) { 400 | String uri = WEATHER_API + "?citykey=" + cityId; 401 | return this.doGetWeatherData(uri); 402 | } 403 | 404 | @Override 405 | public WeatherResponse getDataByCityName(String cityName) { 406 | String uri = WEATHER_API + "?city=" + cityName; 407 | return this.doGetWeatherData(uri); 408 | } 409 | 410 | private WeatherResponse doGetWeatherData(String uri) { 411 | ResponseEntity response = restTemplate.getForEntity(uri, String.class); 412 | String strBody = null; 413 | 414 | if (response.getStatusCodeValue() == 200) { 415 | strBody = response.getBody(); 416 | } 417 | 418 | ObjectMapper mapper = new ObjectMapper(); 419 | WeatherResponse weather = null; 420 | 421 | try { 422 | weather = mapper.readValue(strBody, WeatherResponse.class); 423 | } catch (IOException e) { 424 | e.printStackTrace(); 425 | } 426 | 427 | return weather; 428 | } 429 | 430 | } 431 | ``` 432 | 433 | 返回的天气信息采用了 Jackson 来进行反序列化成为 WeatherResponse 对象。 434 | 435 | ## 控制器层 436 | 437 | 控制器层暴露了RESTful API 地址。 438 | 439 | ```java 440 | @RestController 441 | @RequestMapping("/weather") 442 | public class WeatherController { 443 | 444 | @Autowired 445 | private WeatherDataService weatherDataService; 446 | 447 | @GetMapping("/cityId/{cityId}") 448 | public WeatherResponse getReportByCityId(@PathVariable("cityId") String cityId) { 449 | return weatherDataService.getDataByCityId(cityId); 450 | } 451 | 452 | @GetMapping("/cityName/{cityName}") 453 | public WeatherResponse getReportByCityName(@PathVariable("cityName") String cityName) { 454 | return weatherDataService.getDataByCityName(cityName); 455 | } 456 | 457 | } 458 | ``` 459 | 460 | `@RestController`自动会将返回的数据,序列化成 JSON数据格式。 461 | 462 | ## 配置类 463 | 464 | RestConfiguration 是 RestTemplate 的配置类。 465 | 466 | ```java 467 | @Configuration 468 | public class RestConfiguration { 469 | 470 | @Autowired 471 | private RestTemplateBuilder builder; 472 | 473 | @Bean 474 | public RestTemplate restTemplate() { 475 | return builder.build(); 476 | } 477 | 478 | } 479 | ``` 480 | 481 | ## 访问API 482 | 483 | 运行项目之后,访问项目的 API : 484 | 485 | * 486 | * 487 | 488 | 489 | 能看到如下的数据返回 490 | 491 | ![weather-data](../../images/msa-boot/weather-data.jpg) 492 | 493 | ## 源码 494 | 495 | 本章节的源码,在`micro-weather-basic`目录下。 -------------------------------------------------------------------------------- /docs/msa-boot/msa-boot-api.md: -------------------------------------------------------------------------------- 1 | # 微服务 API 设计原则 2 | -------------------------------------------------------------------------------- /docs/msa-boot/msa-boot-overview.md: -------------------------------------------------------------------------------- 1 | # 微服务架构概述 2 | 3 | -------------------------------------------------------------------------------- /docs/msa-boot/msa-boot-redis.md: -------------------------------------------------------------------------------- 1 | # 提升微服务的并发访问能力 2 | 3 | 有时,为了提升整个网站的性能,我们会将经常需要访问数据缓存起来,这样,在下次查询的时候,能快速的找到这些数据。 4 | 5 | 缓存的使用与系统的时效性有着非常大的关系。当我们的系统时效性要求不高时,则选择使用缓存是极好的。当,系统要求的时效性比较高时,则并不适合用缓存。 6 | 7 | 本章节,我们将演示如何通过集成Redis服务器来进行数据的缓存,以提高微服务的并发访问能力。 8 | 9 | 天气数据接口,本身时效性不是很高,而且又因为是Web服务,在调用过程中,本身是存在延时的。所以,采用缓存,一方面可以有效减轻访问天气接口服务带来的延时问题,另一方面,也可以减轻天气接口的负担,提高并发访问量。 10 | 11 | 在`micro-weather-basic`的基础上,我们构建了一个`micro-weather-redis`项目,作为示例。 12 | 13 | ## 开发环境 14 | 15 | * Spring Data Redis 1.5.6 16 | * Redis 3.2.100 : 17 | 18 | 19 | ## 项目配置 20 | 21 | 添加 Spring Data Redis 的依赖。 22 | 23 | ```groovy 24 | // 依赖关系 25 | dependencies { 26 | //... 27 | 28 | // 添加 Spring Data Redis 依赖 29 | compile('org.springframework.boot:spring-boot-starter-data-redis') 30 | 31 | //... 32 | } 33 | ``` 34 | 35 | 36 | ## 下载安装、运行 Redis 37 | 38 | 39 | 安装后,默认运行在 地址端口。 40 | 41 | 42 | ## 修改 WeatherDataServiceImpl 43 | 44 | 增加了 StringRedisTemplate 用于操作 Redis。 45 | 46 | 47 | ```java 48 | @Service 49 | public class WeatherDataServiceImpl implements WeatherDataService { 50 | 51 | @Autowired 52 | private RestTemplate restTemplate; 53 | 54 | @Autowired 55 | private StringRedisTemplate stringRedisTemplate; 56 | 57 | private final String WEATHER_API = "http://wthrcdn.etouch.cn/weather_mini"; 58 | 59 | @Override 60 | public WeatherResponse getDataByCityId(String cityId) { 61 | String uri = WEATHER_API + "?citykey=" + cityId; 62 | return this.doGetWeatherData(uri); 63 | } 64 | 65 | @Override 66 | public WeatherResponse getDataByCityName(String cityName) { 67 | String uri = WEATHER_API + "?city=" + cityName; 68 | return this.doGetWeatherData(uri); 69 | } 70 | 71 | /** 72 | * 获取天气数据 73 | * @param uri 74 | * @return 75 | */ 76 | private WeatherResponse doGetWeatherData(String uri) { 77 | 78 | ValueOperations ops = this.stringRedisTemplate.opsForValue(); 79 | String key = uri; 80 | WeatherResponse weather = null; 81 | String strBody = null; 82 | 83 | if (!this.stringRedisTemplate.hasKey(key)) { 84 | System.out.println("Not Found key " + key); 85 | 86 | ResponseEntity response = restTemplate.getForEntity(uri, String.class); 87 | 88 | 89 | if (response.getStatusCodeValue() == 200) { 90 | strBody = response.getBody(); 91 | } 92 | 93 | ops.set(key, strBody, 10L, TimeUnit.SECONDS); 94 | } else { 95 | System.out.println("Found key " + key + ", value=" + ops.get(key)); 96 | 97 | strBody = ops.get(key); 98 | } 99 | 100 | ObjectMapper mapper = new ObjectMapper(); 101 | 102 | try { 103 | weather = mapper.readValue(strBody, WeatherResponse.class); 104 | } catch (IOException e) { 105 | e.printStackTrace(); 106 | } 107 | 108 | return weather; 109 | } 110 | 111 | } 112 | ``` 113 | 114 | 修改了 doGetWeatherData 方法,增加了 Redis 数据的判断。 115 | * 当存在某个key(天气接口的uri,是唯一代表某个地区的天气数据)时,我们就从 Redis 里面拿缓存数据; 116 | * 当不存在某个key(没有初始化数据或者数据过期了),从去天气接口里面去取最新的数据,并初始化到 Redis 中; 117 | * 由于天气数据更新频率的特点(基本上一个小时或者半个小时更新一次),或者,我们在Redis里面设置了 30分钟的超时时间。 118 | 119 | ## 运行 120 | 121 | 多次访问某个天气接口时,来测试效果。 122 | 123 | ``` 124 | Not Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601 125 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 126 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 127 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 128 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 129 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 130 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 131 | Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601, value={"data":{"yesterday":{"date":"5日星期二","high":"高温 32℃","fx":"无持续风向","low":"低温 27℃","fl":"","type":"中雨"},"city":"深圳","aqi":"34","forecast":[{"date":"6日星期三","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"中雨"},{"date":"7日星期四","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"小雨"},{"date":"8日星期五","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"雷阵雨"},{"date":"9日星期六","high":"高温 32℃","fengli":"","low":"低温 27℃","fengxiang":"无持续风向","type":"多云"},{"date":"10日星期天","high":"高温 32℃","fengli":"","low":"低温 26℃","fengxiang":"无持续风向","type":"多云"}],"ganmao":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","wendu":"27"},"status":1000,"desc":"OK"} 132 | Not Found key http://wthrcdn.etouch.cn/weather_mini?citykey=101280601 133 | ``` 134 | 135 | 可以看到,第一次访问接口时,没有找到 Redis 里面的数据,所以,就初始化了数据。 136 | 后面几次访问,都是访问 Redis 里面的数据。最后一次,由于超时了,所以 Redis 里面又没有数据了,所以又会拿天气接口的数据。 137 | 138 | ## 源码 139 | 140 | 本章节的源码,在`micro-weather-redis`目录下。 -------------------------------------------------------------------------------- /docs/msa-boot/msa-boot-store.md: -------------------------------------------------------------------------------- 1 | # 微服务存储设计原则 2 | 3 | -------------------------------------------------------------------------------- /docs/msa-boot/msa-boot.md: -------------------------------------------------------------------------------- 1 | # 微服务 与 Spring Boot 2 | 3 | -------------------------------------------------------------------------------- /docs/references.md: -------------------------------------------------------------------------------- 1 | # 参考资料 2 | 3 | * http://projects.spring.io/spring-cloud/ -------------------------------------------------------------------------------- /docs/register-discover/discover-meaning.md: -------------------------------------------------------------------------------- 1 | # 服务发现的意义 2 | 3 | -------------------------------------------------------------------------------- /docs/register-discover/eureka-in-action.md: -------------------------------------------------------------------------------- 1 | # 实现服务的注册与发现 2 | 3 | 4 | 本章节,我们将创建一个`micro-weather-eureka-client` 作为客户端,并演示如何让将自身向注册服务器进行注册,让其可以其他服务都调用。 5 | 6 | ## 开发环境 7 | 8 | * Gradle 4.0 9 | * Spring Boot 2.0.0.M3 10 | * Spring Cloud Netflix Eureka Client Finchley.M2 11 | 12 | 13 | ## 更改配置 14 | 15 | 增加如下配置: 16 | 17 | ```groovy 18 | dependencies { 19 | //... 20 | 21 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 22 | 23 | //... 24 | } 25 | ``` 26 | 27 | ## 一个最简单的 Eureka Client 28 | 29 | ```java 30 | @SpringBootApplication 31 | @EnableDiscoveryClient 32 | @RestController 33 | public class Application { 34 | 35 | @RequestMapping("/hello") 36 | public String home() { 37 | return "Hello world"; 38 | } 39 | 40 | public static void main(String[] args) { 41 | SpringApplication.run(Application.class, args); 42 | } 43 | } 44 | ``` 45 | 46 | 项目配置: 47 | 48 | ``` 49 | spring.application.name: micro-weather-eureka-client 50 | 51 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 52 | ``` 53 | 54 | ## 运行 55 | 56 | 分别在 8081 和 8082 上启动了客户端示例。 57 | 58 | ```java 59 | java -jar micro-weather-eureka-client-1.0.0.jar --server.port=8081 60 | 61 | java -jar micro-weather-eureka-client-1.0.0.jar --server.port=8082 62 | ``` 63 | 64 | 可以在 Eureka Server 上看到这两个实体的信息。 65 | 66 | ![eurake-client](../../images/register-discover/eurake-client.jpg) 67 | 68 | ## 源码 69 | 70 | 本章节源码,见`micro-weather-eureka-server` 和 `micro-weather-eureka-client` 。 -------------------------------------------------------------------------------- /docs/register-discover/eureka.md: -------------------------------------------------------------------------------- 1 | # 如何集成Eureka 2 | 3 | 本章节,我们将创建一个`micro-weather-eureka-server` 作为注册服务器。 4 | 5 | 6 | ## 开发环境 7 | 8 | * Gradle 4.0 9 | * Spring Boot 2.0.0.M3 10 | * Spring Cloud Netflix Eureka Server Finchley.M2 11 | 12 | ## 从 Spring Initializr 进行项目的初始化 13 | 14 | 访问 进行项目的初始化。 15 | 16 | ![eurake-start](../../images/register-discover/eurake-start.jpg) 17 | 18 | ## 更改配置 19 | 20 | 根据下面两个博客的指引来配置,加速项目的构建。 21 | 22 | * Gradle Wrapper 引用本地的发布包 : 23 | * 使用Maven镜像 : 24 | 25 | ## 启用 Eureka Server 26 | 27 | 为启用 Eureka Server ,在 Application 上增加`@EnableEurekaServer`注解即可。 28 | 29 | ```java 30 | @SpringBootApplication 31 | @EnableEurekaServer 32 | public class Application { 33 | 34 | public static void main(String[] args) { 35 | SpringApplication.run(Application.class, args); 36 | } 37 | } 38 | ``` 39 | 40 | ## 修改项目配置 41 | 42 | 修改 application.properties,增加如下配置。 43 | 44 | ``` 45 | server.port: 8761 46 | 47 | eureka.instance.hostname: localhost 48 | eureka.client.registerWithEureka: false 49 | eureka.client.fetchRegistry: false 50 | eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 51 | ``` 52 | 53 | 其中: 54 | 55 | * server.port: 指明了应用启动的端口号 56 | * eureka.instance.hostname: 应用的主机名称 57 | * eureka.client.registerWithEureka: 值为`false`意味着自身仅作为服务器,不作为客户端 58 | * eureka.client.fetchRegistry: 值为`false`意味着无需注册自身 59 | * eureka.client.serviceUrl.defaultZone: 指明了应用的URL 60 | 61 | ## 启动 62 | 63 | 启动应用,访问,可以看到 Eureka Server 自带的 UI 管理界面。 64 | 65 | ![eurake-ui](../../images/register-discover/eurake-ui.jpg) 66 | -------------------------------------------------------------------------------- /docs/register-discover/register-discover.md: -------------------------------------------------------------------------------- 1 | # 微服务的注册与发现 2 | -------------------------------------------------------------------------------- /docs/spring-cloud/spring-cloud-and-boot.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud 与 Spring Boot 的关系 2 | 3 | Spring Boot 是构建 Spring Cloud 架构的基石,是一种快速启动项目的方式。 4 | 5 | Spring Cloud 对应于 Spring Boot 版本,由以下依赖关系。 6 | 7 | Finchley builds and works with Spring Boot 2.0.x, and is not expected to work with Spring Boot 1.5.x. 8 | 9 | The Dalston and Edgware release trains build on Spring Boot 1.5.x, and are not expected to work with Spring Boot 2.0.x. 10 | 11 | The Camden release train builds on Spring Boot 1.4.x, but is also tested with 1.5.x. 12 | 13 | The Brixton release train builds on Spring Boot 1.3.x, but is also tested with 1.4.x. 14 | 15 | The Angel release train builds on Spring Boot 1.2.x, and is incompatible in some areas with Spring Boot 1.3.x. Brixton builds on Spring Boot 1.3.x and is similarly incompatible with 1.2.x. Some libraries and most apps built on Angel will run fine on Brixton, but changes will be required anywhere that the OAuth2 features from spring-cloud-security 1.0.x are used (they were mostly moved to Spring Boot in 1.3.0). 16 | 17 | Use your dependency management tools to control the version. If you are using Maven remember that the first version declared wins, so declare the BOMs in order, with the first one usually being the most recent (e.g. if you want to use Spring Boot 1.3.6 with Brixton.RELEASE, put the Boot BOM first). The same rule applies to Gradle if you use the Spring dependency management plugin. 18 | 19 | NOTE: The release train contains a spring-cloud-dependencies as well as the spring-cloud-starter-parent. You can use the parent as you would the spring-boot-starter-parent (if you are using Maven). If you only need dependency management, the "dependencies" version is a BOM-only version of the same thing (it just contains dependency management and no plugin declarations or direct references to Spring or Spring Boot). If you are using the Spring Boot parent POM, then you can use the BOM from Spring Cloud. The opposite is not true: using the Cloud parent makes it impossible, or at least unreliable, to also use the Boot BOM to change the version of Spring Boot and its dependencies. -------------------------------------------------------------------------------- /docs/spring-cloud/spring-cloud-config.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud 入门配置 2 | 3 | 在项目中开始使用 Spring Cloud 的推荐方法是使用依赖关系管理系统,比如,使用 Maven 或者 Gradle 构建。 4 | 5 | 6 | ## Maven 配置 7 | 8 | 以下是一个基本的 Spring Boot 项目的基本 Maven 配置: 9 | 10 | ```xml 11 | 12 | 14 | 4.0.0 15 | 16 | com.waylau.spring 17 | cloud 18 | 0.0.1-SNAPSHOT 19 | jar 20 | 21 | basic-maven 22 | Basic project for Maven 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-parent 27 | 1.5.6.RELEASE 28 | 29 | 30 | 31 | 32 | UTF-8 33 | UTF-8 34 | 1.8 35 | 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | 61 | ``` 62 | 63 | 在此基础之上,您可以按需添加不同的依赖,以使您的应用程序增强功能。 64 | 65 | ## Gradle 配置 66 | 67 | 68 | 以下是一个基本的 Spring Boot 项目的基本 Maven 配置: 69 | 70 | ```groovy 71 | buildscript { 72 | ext { 73 | springBootVersion = '1.5.6.RELEASE' 74 | } 75 | repositories { 76 | mavenCentral() 77 | } 78 | dependencies { 79 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 80 | } 81 | } 82 | 83 | apply plugin: 'java' 84 | apply plugin: 'eclipse' 85 | apply plugin: 'org.springframework.boot' 86 | 87 | version = '0.0.1-SNAPSHOT' 88 | sourceCompatibility = 1.8 89 | 90 | repositories { 91 | mavenCentral() 92 | } 93 | 94 | 95 | dependencies { 96 | compile('org.springframework.boot:spring-boot-starter-web') 97 | testCompile('org.springframework.boot:spring-boot-starter-test') 98 | } 99 | ``` 100 | 101 | 102 | 103 | 在此基础之上,您可以按需添加不同的依赖,以使您的应用程序增强功能。 104 | 105 | 106 | ## 声明式方法 107 | 108 | Spring Cloud 采用声明的方法,通常只需要一个类路径更改和/或注释即可获得很多功能。下面是 Spring Boot 最简单的应用程序示例: 109 | 110 | 111 | ```java 112 | @SpringBootApplication 113 | public class Application { 114 | 115 | public static void main(String[] args) { 116 | SpringApplication.run(Application.class, args); 117 | } 118 | } 119 | ``` 120 | 121 | ## 自动生成项目 122 | 123 | Spring 官方提供了基于 Web 的 Spring Initializr 项目,用于 Spring 项目的快速生成。作为项目的初始化,采用 Spring Initializr 是个不错的选择。访问 ,填入相关的项目信息,选择合适的依赖,即可实现项目源码的下载。而这个过程,你无需关心你的依赖是如何来管理的, Spring Initializr 为你准备好了一切。 124 | 125 | ![start](../../images/spring-cloud/start.jpg) 126 | 127 | ## 源码 128 | 129 | 本章节源码,见`basic-maven` 和 `basic-gradle`。 -------------------------------------------------------------------------------- /docs/spring-cloud/spring-cloud-overview.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud 简介 2 | 3 | 4 | [Spring Cloud](http://projects.spring.io/spring-cloud/) 为开发人员提供了快速构建分布式系统中一些常见模式的工具,例如: 5 | 6 | * 配置管理 7 | * 服务注册与发现 8 | * 断路器 9 | * 智能路由 10 | * 服务间调用 11 | * 负载均衡 12 | * 微代理 13 | * 控制总线 14 | * 一次性令牌 15 | * 全局锁 16 | * 领导选举 17 | * 分布式会话 18 | * 集群状态 19 | * 分布式消息 20 | * ...... 21 | 22 | 使用 Spring Cloud 开发人员可以开箱即用的实现这些模式的服务和应用程序。这些服务可以任何环境下运行,包括分布式环境,也包括开发人员自己的笔记本电脑、裸机数据中心,以及 Cloud Foundry 等托管平台。 23 | 24 | Spring Cloud 基于 Spring Boot 来进行构建服务。并可以将轻松集成第三方类库,增强应用程序的行为。您可以利用基本的默认行为快速入门,然后在需要时,您可以配置或扩展以创建自定义解决方案。 25 | 26 | **注**:有关 Spring Boot 的内容,可以参阅笔者所著的《Spring Boot 教程》() -------------------------------------------------------------------------------- /docs/spring-cloud/spring-cloud-projects.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud 的子项目介绍 2 | 3 | Spring Cloud 由以下子项目组成。 4 | 5 | ## Spring Cloud Config 6 | 7 | 8 | Centralized external configuration management backed by a git repository. The configuration resources map directly to Spring `Environment` but could be used by non-Spring applications if desired. 9 | 10 | 项目地址为:。 11 | 12 | ## Spring Cloud Netflix 13 | Integration with various Netflix OSS components (Eureka, Hystrix, Zuul, Archaius, etc.). 14 | 15 | 项目地址为:。 16 | 17 | ## Spring Cloud Bus 18 | An event bus for linking services and service instances together with distributed messaging. Useful for propagating state changes across a cluster (e.g. config change events). 19 | 20 | 项目地址为:。 21 | 22 | ## Spring Cloud for Cloud Foundry 23 | Integrates your application with Pivotal Cloudfoundry. Provides a service discovery implementation and also makes it easy to implement SSO and OAuth2 protected resources, and also to create a Cloudfoundry service broker. 24 | 25 | 项目地址为:。 26 | 27 | ## Spring Cloud Cloud Foundry Service Broker 28 | Provides a starting point for building a service broker that manages a Cloud Foundry managed service. 29 | 30 | 项目地址为:。 31 | 32 | ## Spring Cloud Cluster 33 | Leadership election and common stateful patterns with an abstraction and implementation for Zookeeper, Redis, Hazelcast, Consul. 34 | 35 | 项目地址为:。 36 | 37 | ## Spring Cloud Consul 38 | Service discovery and configuration management with Hashicorp Consul. 39 | 40 | 项目地址为:。 41 | 42 | ## Spring Cloud Security 43 | Provides support for load-balanced OAuth2 rest client and authentication header relays in a Zuul proxy. 44 | 45 | 项目地址为:。 46 | 47 | ## Spring Cloud Sleuth 48 | Distributed tracing for Spring Cloud applications, compatible with Zipkin, HTrace and log-based (e.g. ELK) tracing. 49 | 50 | 项目地址为:。 51 | 52 | ## Spring Cloud Data Flow 53 | A cloud-native orchestration service for composable microservice applications on modern runtimes. Easy-to-use DSL, drag-and-drop GUI, and REST-APIs together simplifies the overall orchestration of microservice based data pipelines. 54 | 55 | 项目地址为:。 56 | 57 | ## Spring Cloud Stream 58 | A lightweight event-driven microservices framework to quickly build applications that can connect to external systems. Simple declarative model to send and receive messages using Apache Kafka or RabbitMQ between Spring Boot apps. 59 | 60 | 项目地址为:。 61 | 62 | ## Spring Cloud Stream App Starters 63 | Spring Cloud Stream App Starters are Spring Boot based Spring Integration applications that provide integration with external systems. 64 | 65 | 项目地址为:。 66 | 67 | ## Spring Cloud Task 68 | A short-lived microservices framework to quickly build applications that perform finite amounts of data processing. Simple declarative for adding both functional and non-functional features to Spring Boot apps. 69 | 70 | 项目地址为:。 71 | 72 | ## Spring Cloud Task App Starters 73 | Spring Cloud Task App Starters are Spring Boot applications that may be any process including Spring Batch jobs that do not run forever, and they end/stop after a finite period of data processing. 74 | 75 | 项目地址为:。 76 | 77 | ## Spring Cloud Zookeeper 78 | Service discovery and configuration management with Apache Zookeeper. 79 | 80 | 项目地址为:。 81 | 82 | ## Spring Cloud for Amazon Web Services 83 | Easy integration with hosted Amazon Web Services. It offers a convenient way to interact with AWS provided services using well-known Spring idioms and APIs, such as the messaging or caching API. Developers can build their application around the hosted services without having to care about infrastructure or maintenance. 84 | 85 | 项目地址为:。 86 | 87 | ## Spring Cloud Connectors 88 | Makes it easy for PaaS applications in a variety of platforms to connect to backend services like databases and message brokers (the project formerly known as "Spring Cloud"). 89 | 90 | 项目地址为:。 91 | 92 | ## Spring Cloud Starters 93 | Spring Boot-style starter projects to ease dependency management for consumers of Spring Cloud. (Discontinued as a project and merged with the other projects after Angel.SR2.) 94 | 95 | 项目地址为:。 96 | 97 | ## Spring Cloud CLI 98 | Spring Boot CLI plugin for creating Spring Cloud component applications quickly in Groovy 99 | 100 | 项目地址为:。 101 | 102 | ## Spring Cloud Contract 103 | Spring Cloud Contract is an umbrella project holding solutions that help users in successfully implementing the Consumer Driven Contracts approach. 104 | 105 | 项目地址为:。 106 | -------------------------------------------------------------------------------- /docs/spring-cloud/spring-cloud.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud 介绍 2 | 3 | -------------------------------------------------------------------------------- /images/api-gateway/api-gateway-eureka.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/api-gateway/api-gateway-eureka.jpg -------------------------------------------------------------------------------- /images/centralized-configuration/config-github.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/centralized-configuration/config-github.jpg -------------------------------------------------------------------------------- /images/centralized-configuration/micro-weather-config-client.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/centralized-configuration/micro-weather-config-client.jpg -------------------------------------------------------------------------------- /images/comsumer/comsumer-eureka.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/comsumer/comsumer-eureka.jpg -------------------------------------------------------------------------------- /images/msa-boot/weather-data.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/msa-boot/weather-data.jpg -------------------------------------------------------------------------------- /images/register-discover/eurake-client.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/register-discover/eurake-client.jpg -------------------------------------------------------------------------------- /images/register-discover/eurake-start.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/register-discover/eurake-start.jpg -------------------------------------------------------------------------------- /images/register-discover/eurake-ui.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/register-discover/eurake-ui.jpg -------------------------------------------------------------------------------- /images/spring-cloud-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/spring-cloud-logo.png -------------------------------------------------------------------------------- /images/spring-cloud/start.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/images/spring-cloud/start.jpg -------------------------------------------------------------------------------- /samples/basic-gradle/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /samples/basic-gradle/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.6.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | 17 | version = '0.0.1-SNAPSHOT' 18 | sourceCompatibility = 1.8 19 | 20 | repositories { 21 | mavenCentral() 22 | } 23 | 24 | 25 | dependencies { 26 | compile('org.springframework.boot:spring-boot-starter-web') 27 | testCompile('org.springframework.boot:spring-boot-starter-test') 28 | } 29 | -------------------------------------------------------------------------------- /samples/basic-gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/basic-gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/basic-gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | -------------------------------------------------------------------------------- /samples/basic-gradle/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/basic-gradle/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/basic-gradle/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/basic-gradle/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/basic-gradle/src/main/resources/application.properties -------------------------------------------------------------------------------- /samples/basic-gradle/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/basic-maven/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /samples/basic-maven/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/basic-maven/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /samples/basic-maven/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /samples/basic-maven/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /samples/basic-maven/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /samples/basic-maven/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.waylau.spring 7 | cloud 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | cloud 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.6.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /samples/basic-maven/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/basic-maven/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/basic-maven/src/main/resources/application.properties -------------------------------------------------------------------------------- /samples/basic-maven/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.6.RELEASE' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'eclipse' 16 | apply plugin: 'org.springframework.boot' 17 | 18 | version = '1.0.0' 19 | sourceCompatibility = 1.8 20 | 21 | repositories { 22 | //mavenCentral() 23 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | // 添加 Apache HttpClient 依赖 30 | compile('org.apache.httpcomponents:httpclient:4.5.3') 31 | testCompile('org.springframework.boot:spring-boot-starter-test') 32 | } 33 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-basic/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-basic/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/config/RestConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.waylau.spring.cloud.config; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.web.client.RestTemplateBuilder; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * REST配置. 14 | * 15 | * @since 1.0.0 2017年9月2日 16 | * @author Way Lau 17 | */ 18 | @Configuration 19 | public class RestConfiguration { 20 | 21 | @Autowired 22 | private RestTemplateBuilder builder; 23 | 24 | @Bean 25 | public RestTemplate restTemplate() { 26 | return builder.build(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/controller/WeatherController.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.waylau.spring.cloud.service.WeatherDataService; 10 | import com.waylau.spring.cloud.vo.WeatherResponse; 11 | 12 | /** 13 | * 天气控制器. 14 | * 15 | * @since 1.0.0 2017年9月2日 16 | * @author Way Lau 17 | */ 18 | @RestController 19 | @RequestMapping("/weather") 20 | public class WeatherController { 21 | 22 | @Autowired 23 | private WeatherDataService weatherDataService; 24 | 25 | @GetMapping("/cityId/{cityId}") 26 | public WeatherResponse getReportByCityId(@PathVariable("cityId") String cityId) { 27 | return weatherDataService.getDataByCityId(cityId); 28 | } 29 | 30 | @GetMapping("/cityName/{cityName}") 31 | public WeatherResponse getReportByCityName(@PathVariable("cityName") String cityName) { 32 | return weatherDataService.getDataByCityName(cityName); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/service/WeatherDataService.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.service; 2 | 3 | import com.waylau.spring.cloud.vo.WeatherResponse; 4 | 5 | /** 6 | * 天气数据服务. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public interface WeatherDataService { 12 | 13 | /** 14 | * 根据城市ID查询天气数据 15 | * @param cityId 16 | * @return 17 | */ 18 | WeatherResponse getDataByCityId(String cityId); 19 | 20 | /** 21 | * 根据城市名称查询天气数据 22 | * @param cityId 23 | * @return 24 | */ 25 | WeatherResponse getDataByCityName(String cityName); 26 | } 27 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/service/WeatherDataServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.waylau.spring.cloud.service; 5 | 6 | import java.io.IOException; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | import com.waylau.spring.cloud.vo.WeatherResponse; 15 | 16 | /** 17 | * 天气数据服务. 18 | * 19 | * @since 1.0.0 2017年9月2日 20 | * @author Way Lau 21 | */ 22 | @Service 23 | public class WeatherDataServiceImpl implements WeatherDataService { 24 | 25 | @Autowired 26 | private RestTemplate restTemplate; 27 | 28 | private final String WEATHER_API = "http://wthrcdn.etouch.cn/weather_mini"; 29 | 30 | @Override 31 | public WeatherResponse getDataByCityId(String cityId) { 32 | String uri = WEATHER_API + "?citykey=" + cityId; 33 | return this.doGetWeatherData(uri); 34 | } 35 | 36 | @Override 37 | public WeatherResponse getDataByCityName(String cityName) { 38 | String uri = WEATHER_API + "?city=" + cityName; 39 | return this.doGetWeatherData(uri); 40 | } 41 | 42 | private WeatherResponse doGetWeatherData(String uri) { 43 | ResponseEntity response = restTemplate.getForEntity(uri, String.class); 44 | String strBody = null; 45 | 46 | if (response.getStatusCodeValue() == 200) { 47 | strBody = response.getBody(); 48 | } 49 | 50 | ObjectMapper mapper = new ObjectMapper(); 51 | WeatherResponse weather = null; 52 | 53 | try { 54 | weather = mapper.readValue(strBody, WeatherResponse.class); 55 | } catch (IOException e) { 56 | e.printStackTrace(); 57 | } 58 | 59 | return weather; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/vo/Forecast.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 未来天气信息. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public class Forecast implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | private String date; 16 | private String high; 17 | private String fengxiang; 18 | private String low; 19 | private String fengli; 20 | private String type; 21 | 22 | public String getDate() { 23 | return date; 24 | } 25 | 26 | public void setDate(String date) { 27 | this.date = date; 28 | } 29 | 30 | public String getHigh() { 31 | return high; 32 | } 33 | 34 | public void setHigh(String high) { 35 | this.high = high; 36 | } 37 | 38 | public String getFengxiang() { 39 | return fengxiang; 40 | } 41 | 42 | public void setFengxiang(String fengxiang) { 43 | this.fengxiang = fengxiang; 44 | } 45 | 46 | public String getLow() { 47 | return low; 48 | } 49 | 50 | public void setLow(String low) { 51 | this.low = low; 52 | } 53 | 54 | public String getFengli() { 55 | return fengli; 56 | } 57 | 58 | public void setFengli(String fengli) { 59 | this.fengli = fengli; 60 | } 61 | 62 | public String getType() { 63 | return type; 64 | } 65 | 66 | public void setType(String type) { 67 | this.type = type; 68 | } 69 | 70 | public Forecast() { 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/vo/Weather.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * 天气信息. 8 | * 9 | * @since 1.0.0 2017年4月29日 10 | * @author Way Lau 11 | */ 12 | public class Weather implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | private String city; 17 | private String aqi; 18 | private String wendu; 19 | private String ganmao; 20 | private Yesterday yesterday; 21 | private List forecast; 22 | 23 | public String getCity() { 24 | return city; 25 | } 26 | public void setCity(String city) { 27 | this.city = city; 28 | } 29 | public String getAqi() { 30 | return aqi; 31 | } 32 | public void setAqi(String aqi) { 33 | this.aqi = aqi; 34 | } 35 | public String getWendu() { 36 | return wendu; 37 | } 38 | public void setWendu(String wendu) { 39 | this.wendu = wendu; 40 | } 41 | public String getGanmao() { 42 | return ganmao; 43 | } 44 | public void setGanmao(String ganmao) { 45 | this.ganmao = ganmao; 46 | } 47 | public Yesterday getYesterday() { 48 | return yesterday; 49 | } 50 | public void setYesterday(Yesterday yesterday) { 51 | this.yesterday = yesterday; 52 | } 53 | public List getForecast() { 54 | return forecast; 55 | } 56 | public void setForecast(List forecast) { 57 | this.forecast = forecast; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/vo/WeatherResponse.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 返回消息对象. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public class WeatherResponse implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | private Weather data; // 消息数据 16 | private String status; // 消息状态 17 | private String desc; // 消息描述 18 | 19 | public Weather getData() { 20 | return data; 21 | } 22 | 23 | public void setData(Weather data) { 24 | this.data = data; 25 | } 26 | 27 | public String getStatus() { 28 | return status; 29 | } 30 | 31 | public void setStatus(String status) { 32 | this.status = status; 33 | } 34 | 35 | public String getDesc() { 36 | return desc; 37 | } 38 | 39 | public void setDesc(String desc) { 40 | this.desc = desc; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/java/com/waylau/spring/cloud/vo/Yesterday.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 昨日天气信息. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public class Yesterday implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | private String date; 16 | private String high; 17 | private String fx; 18 | private String low; 19 | private String fl; 20 | private String type; 21 | 22 | public Yesterday() { 23 | 24 | } 25 | 26 | public String getDate() { 27 | return date; 28 | } 29 | 30 | public void setDate(String date) { 31 | this.date = date; 32 | } 33 | 34 | public String getHigh() { 35 | return high; 36 | } 37 | 38 | public void setHigh(String high) { 39 | this.high = high; 40 | } 41 | 42 | public String getFx() { 43 | return fx; 44 | } 45 | 46 | public void setFx(String fx) { 47 | this.fx = fx; 48 | } 49 | 50 | public String getLow() { 51 | return low; 52 | } 53 | 54 | public void setLow(String low) { 55 | this.low = low; 56 | } 57 | 58 | public String getFl() { 59 | return fl; 60 | } 61 | 62 | public void setFl(String fl) { 63 | this.fl = fl; 64 | } 65 | 66 | public String getType() { 67 | return type; 68 | } 69 | 70 | public void setType(String type) { 71 | this.type = type; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-basic/src/main/resources/application.properties -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-basic/src/test/java/com/waylau/spring/cloud/service/WeatherDataServiceTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.service; 2 | 3 | import org.junit.Test; 4 | 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | import com.waylau.spring.cloud.vo.WeatherResponse; 11 | /** 12 | * 天气服务测试. 13 | * 14 | * @since 1.0.0 2017年9月4日 15 | * @author Way Lau 16 | */ 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest 19 | public class WeatherDataServiceTests { 20 | 21 | @Autowired 22 | private WeatherDataService weatherDataService; 23 | 24 | @Test 25 | public void testGetDataByCityId() { 26 | WeatherResponse response = weatherDataService.getDataByCityId("101280601"); 27 | System.out.println(response.getDesc()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /samples/micro-weather-config-client/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-config-client/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.M3' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | maven { url "https://repo.spring.io/milestone" } 9 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | version = '1.0.0' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | //mavenCentral() 26 | maven { url "https://repo.spring.io/snapshot" } 27 | maven { url "https://repo.spring.io/milestone" } 28 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 29 | } 30 | 31 | ext { 32 | springCloudVersion = 'Finchley.M2' 33 | } 34 | 35 | dependencies { 36 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 37 | compile('org.springframework.cloud:spring-cloud-starter-config') 38 | testCompile('org.springframework.boot:spring-boot-starter-test') 39 | } 40 | 41 | dependencyManagement { 42 | imports { 43 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /samples/micro-weather-config-client/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-config-client/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-config-client/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-config-client/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-config-client/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-config-client/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /samples/micro-weather-config-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name: micro-weather-config-client 2 | server.port=8089 3 | 4 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 5 | 6 | spring.cloud.config.profile=dev 7 | spring.cloud.config.uri= http://localhost:8888/ -------------------------------------------------------------------------------- /samples/micro-weather-config-client/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | @RunWith(SpringRunner.class) 10 | @SpringBootTest 11 | public class ApplicationTests { 12 | 13 | @Value("${auther}") 14 | private String auther; 15 | 16 | @Test 17 | public void contextLoads() { 18 | System.out.println(auther); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /samples/micro-weather-config-server/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-config-server/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.M3' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | maven { url "https://repo.spring.io/milestone" } 9 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | version = '1.0.0' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | //mavenCentral() 26 | maven { url "https://repo.spring.io/snapshot" } 27 | maven { url "https://repo.spring.io/milestone" } 28 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 29 | } 30 | 31 | ext { 32 | springCloudVersion = 'Finchley.M2' 33 | } 34 | 35 | dependencies { 36 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 37 | compile('org.springframework.cloud:spring-cloud-config-server') 38 | testCompile('org.springframework.boot:spring-boot-starter-test') 39 | } 40 | 41 | dependencyManagement { 42 | imports { 43 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /samples/micro-weather-config-server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-config-server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-config-server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-config-server/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-config-server/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-config-server/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.config.server.EnableConfigServer; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableConfigServer 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /samples/micro-weather-config-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name: micro-weather-config-server 2 | server.port=8888 3 | 4 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 5 | 6 | spring.cloud.config.server.git.uri=https://github.com/waylau/spring-cloud-tutorial 7 | spring.cloud.config.server.git.searchPaths=config -------------------------------------------------------------------------------- /samples/micro-weather-config-server/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.M3' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | maven { url "https://repo.spring.io/milestone" } 9 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | version = '1.0.0' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | //mavenCentral() 26 | maven { url "https://repo.spring.io/snapshot" } 27 | maven { url "https://repo.spring.io/milestone" } 28 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 29 | } 30 | 31 | 32 | ext { 33 | springCloudVersion = 'Finchley.M2' 34 | } 35 | 36 | dependencies { 37 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 38 | testCompile('org.springframework.boot:spring-boot-starter-test') 39 | } 40 | 41 | dependencyManagement { 42 | imports { 43 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-eureka-client/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @SpringBootApplication 10 | @EnableDiscoveryClient 11 | @RestController 12 | public class Application { 13 | 14 | @RequestMapping("/hello") 15 | public String home() { 16 | return "Hello world"; 17 | } 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(Application.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name: micro-weather-eureka-client 2 | 3 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 4 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-client/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.M3' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | maven { url "https://repo.spring.io/milestone" } 9 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | version = '1.0.0' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | //mavenCentral() 26 | maven { url "https://repo.spring.io/snapshot" } 27 | maven { url "https://repo.spring.io/milestone" } 28 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 29 | } 30 | 31 | ext { 32 | springCloudVersion = 'Finchley.M2' 33 | } 34 | 35 | dependencies { 36 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server') 37 | testCompile('org.springframework.boot:spring-boot-starter-test') 38 | } 39 | 40 | dependencyManagement { 41 | imports { 42 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-eureka-server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port: 8761 2 | 3 | eureka.instance.hostname: localhost 4 | 5 | # 表示是否将自己注册到Eureka Server上,默认为true,当前应用为Eureka Server所以无需注册 6 | eureka.client.registerWithEureka: false 7 | # 表示是否从Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而设为false。 8 | eureka.client.fetchRegistry: false 9 | # Eureka Server的访问地址,服务注册和client获取服务注册信息均通过该URL,多个服务注册地址用,隔开 10 | eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /samples/micro-weather-eureka-server/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.M3' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | maven { url "https://repo.spring.io/milestone" } 9 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | version = '1.0.0' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | //mavenCentral() 26 | maven { url "https://repo.spring.io/snapshot" } 27 | maven { url "https://repo.spring.io/milestone" } 28 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 29 | } 30 | 31 | ext { 32 | springCloudVersion = 'Finchley.M2' 33 | } 34 | 35 | dependencies { 36 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 37 | compile('org.springframework.cloud:spring-cloud-starter-openfeign') 38 | testCompile('org.springframework.boot:spring-boot-starter-test') 39 | } 40 | 41 | dependencyManagement { 42 | imports { 43 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-feign/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-feign/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /samples/micro-weather-feign/src/main/java/com/waylau/spring/cloud/service/HelloClient.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.service; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | /** 8 | * Hello Client 9 | * 10 | * @since 1.0.0 2017年9月17日 11 | * @author Way Lau 12 | */ 13 | @FeignClient("micro-weather-eureka-client") 14 | public interface HelloClient { 15 | @RequestMapping(method = RequestMethod.GET, value = "/hello") 16 | String getHello(); 17 | } 18 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name: micro-weather-feign 2 | 3 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 4 | 5 | feign.client.config.feignName.connectTimeout: 5000 6 | feign.client.config.feignName.readTimeout: 5000 -------------------------------------------------------------------------------- /samples/micro-weather-feign/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-feign/src/test/java/com/waylau/spring/cloud/service/HelloClientTest.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | /** 10 | * HelloClient Test. 11 | * 12 | * @since 1.0.0 2017年9月17日 13 | * @author Way Lau 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class HelloClientTest { 18 | 19 | @Autowired 20 | private HelloClient helloClient; 21 | 22 | @Test 23 | public void testHello() { 24 | String hello = helloClient.getHello(); 25 | System.out.println(hello); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '1.5.6.RELEASE' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 8 | } 9 | dependencies { 10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 11 | } 12 | } 13 | 14 | apply plugin: 'java' 15 | apply plugin: 'eclipse' 16 | apply plugin: 'org.springframework.boot' 17 | 18 | version = '1.0.0' 19 | sourceCompatibility = 1.8 20 | 21 | repositories { 22 | //mavenCentral() 23 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 24 | } 25 | 26 | 27 | dependencies { 28 | compile('org.springframework.boot:spring-boot-starter-web') 29 | // 添加 Apache HttpClient 依赖 30 | compile('org.apache.httpcomponents:httpclient:4.5.3') 31 | // 添加 Apache HttpClient 依赖 32 | compile('org.springframework.boot:spring-boot-starter-data-redis') 33 | testCompile('org.springframework.boot:spring-boot-starter-test') 34 | } 35 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-redis/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-redis/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/config/RestConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.waylau.spring.cloud.config; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.web.client.RestTemplateBuilder; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * REST配置. 14 | * 15 | * @since 1.0.0 2017年9月2日 16 | * @author Way Lau 17 | */ 18 | @Configuration 19 | public class RestConfiguration { 20 | 21 | @Autowired 22 | private RestTemplateBuilder builder; 23 | 24 | @Bean 25 | public RestTemplate restTemplate() { 26 | return builder.build(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/controller/WeatherController.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.waylau.spring.cloud.service.WeatherDataService; 10 | import com.waylau.spring.cloud.vo.WeatherResponse; 11 | 12 | /** 13 | * 天气控制器. 14 | * 15 | * @since 1.0.0 2017年9月2日 16 | * @author Way Lau 17 | */ 18 | @RestController 19 | @RequestMapping("/weather") 20 | public class WeatherController { 21 | 22 | @Autowired 23 | private WeatherDataService weatherDataService; 24 | 25 | @GetMapping("/cityId/{cityId}") 26 | public WeatherResponse getReportByCityId(@PathVariable("cityId") String cityId) { 27 | return weatherDataService.getDataByCityId(cityId); 28 | } 29 | 30 | @GetMapping("/cityName/{cityName}") 31 | public WeatherResponse getReportByCityName(@PathVariable("cityName") String cityName) { 32 | return weatherDataService.getDataByCityName(cityName); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/service/WeatherDataService.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.service; 2 | 3 | import com.waylau.spring.cloud.vo.WeatherResponse; 4 | 5 | /** 6 | * 天气数据服务. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public interface WeatherDataService { 12 | 13 | /** 14 | * 根据城市ID查询天气数据 15 | * @param cityId 16 | * @return 17 | */ 18 | WeatherResponse getDataByCityId(String cityId); 19 | 20 | /** 21 | * 根据城市名称查询天气数据 22 | * @param cityId 23 | * @return 24 | */ 25 | WeatherResponse getDataByCityName(String cityName); 26 | } 27 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/service/WeatherDataServiceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.waylau.spring.cloud.service; 5 | 6 | import java.io.IOException; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.data.redis.core.StringRedisTemplate; 11 | import org.springframework.data.redis.core.ValueOperations; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | import com.fasterxml.jackson.databind.ObjectMapper; 17 | import com.waylau.spring.cloud.vo.WeatherResponse; 18 | 19 | /** 20 | * 天气数据服务. 21 | * 22 | * @since 1.0.0 2017年9月2日 23 | * @author Way Lau 24 | */ 25 | @Service 26 | public class WeatherDataServiceImpl implements WeatherDataService { 27 | 28 | @Autowired 29 | private RestTemplate restTemplate; 30 | 31 | @Autowired 32 | private StringRedisTemplate stringRedisTemplate; 33 | 34 | private final String WEATHER_API = "http://wthrcdn.etouch.cn/weather_mini"; 35 | 36 | @Override 37 | public WeatherResponse getDataByCityId(String cityId) { 38 | String uri = WEATHER_API + "?citykey=" + cityId; 39 | return this.doGetWeatherData(uri); 40 | } 41 | 42 | @Override 43 | public WeatherResponse getDataByCityName(String cityName) { 44 | String uri = WEATHER_API + "?city=" + cityName; 45 | return this.doGetWeatherData(uri); 46 | } 47 | 48 | /** 49 | * 获取天气数据 50 | * @param uri 51 | * @return 52 | */ 53 | private WeatherResponse doGetWeatherData(String uri) { 54 | 55 | ValueOperations ops = this.stringRedisTemplate.opsForValue(); 56 | String key = uri; 57 | WeatherResponse weather = null; 58 | String strBody = null; 59 | 60 | // Redis 里有数据就取 Redis 的数据,否则取天气接口的数据 61 | if (!this.stringRedisTemplate.hasKey(key)) { 62 | System.out.println("Not Found key " + key); 63 | 64 | ResponseEntity response = restTemplate.getForEntity(uri, String.class); 65 | 66 | 67 | if (response.getStatusCodeValue() == 200) { 68 | strBody = response.getBody(); 69 | } 70 | 71 | ops.set(key, strBody, 30L, TimeUnit.MINUTES); // 超时时间 72 | } else { 73 | System.out.println("Found key " + key + ", value=" + ops.get(key)); 74 | 75 | strBody = ops.get(key); 76 | } 77 | 78 | ObjectMapper mapper = new ObjectMapper(); 79 | 80 | try { 81 | weather = mapper.readValue(strBody, WeatherResponse.class); 82 | } catch (IOException e) { 83 | e.printStackTrace(); 84 | } 85 | 86 | return weather; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/vo/Forecast.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 未来天气信息. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public class Forecast implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | private String date; 16 | private String high; 17 | private String fengxiang; 18 | private String low; 19 | private String fengli; 20 | private String type; 21 | 22 | public String getDate() { 23 | return date; 24 | } 25 | 26 | public void setDate(String date) { 27 | this.date = date; 28 | } 29 | 30 | public String getHigh() { 31 | return high; 32 | } 33 | 34 | public void setHigh(String high) { 35 | this.high = high; 36 | } 37 | 38 | public String getFengxiang() { 39 | return fengxiang; 40 | } 41 | 42 | public void setFengxiang(String fengxiang) { 43 | this.fengxiang = fengxiang; 44 | } 45 | 46 | public String getLow() { 47 | return low; 48 | } 49 | 50 | public void setLow(String low) { 51 | this.low = low; 52 | } 53 | 54 | public String getFengli() { 55 | return fengli; 56 | } 57 | 58 | public void setFengli(String fengli) { 59 | this.fengli = fengli; 60 | } 61 | 62 | public String getType() { 63 | return type; 64 | } 65 | 66 | public void setType(String type) { 67 | this.type = type; 68 | } 69 | 70 | public Forecast() { 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/vo/Weather.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * 天气信息. 8 | * 9 | * @since 1.0.0 2017年4月29日 10 | * @author Way Lau 11 | */ 12 | public class Weather implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | private String city; 17 | private String aqi; 18 | private String wendu; 19 | private String ganmao; 20 | private Yesterday yesterday; 21 | private List forecast; 22 | 23 | public String getCity() { 24 | return city; 25 | } 26 | public void setCity(String city) { 27 | this.city = city; 28 | } 29 | public String getAqi() { 30 | return aqi; 31 | } 32 | public void setAqi(String aqi) { 33 | this.aqi = aqi; 34 | } 35 | public String getWendu() { 36 | return wendu; 37 | } 38 | public void setWendu(String wendu) { 39 | this.wendu = wendu; 40 | } 41 | public String getGanmao() { 42 | return ganmao; 43 | } 44 | public void setGanmao(String ganmao) { 45 | this.ganmao = ganmao; 46 | } 47 | public Yesterday getYesterday() { 48 | return yesterday; 49 | } 50 | public void setYesterday(Yesterday yesterday) { 51 | this.yesterday = yesterday; 52 | } 53 | public List getForecast() { 54 | return forecast; 55 | } 56 | public void setForecast(List forecast) { 57 | this.forecast = forecast; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/vo/WeatherResponse.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 返回消息对象. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public class WeatherResponse implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | private Weather data; // 消息数据 16 | private String status; // 消息状态 17 | private String desc; // 消息描述 18 | 19 | public Weather getData() { 20 | return data; 21 | } 22 | 23 | public void setData(Weather data) { 24 | this.data = data; 25 | } 26 | 27 | public String getStatus() { 28 | return status; 29 | } 30 | 31 | public void setStatus(String status) { 32 | this.status = status; 33 | } 34 | 35 | public String getDesc() { 36 | return desc; 37 | } 38 | 39 | public void setDesc(String desc) { 40 | this.desc = desc; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/java/com/waylau/spring/cloud/vo/Yesterday.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 昨日天气信息. 7 | * 8 | * @since 1.0.0 2017年9月2日 9 | * @author Way Lau 10 | */ 11 | public class Yesterday implements Serializable { 12 | 13 | private static final long serialVersionUID = 1L; 14 | 15 | private String date; 16 | private String high; 17 | private String fx; 18 | private String low; 19 | private String fl; 20 | private String type; 21 | 22 | public Yesterday() { 23 | 24 | } 25 | 26 | public String getDate() { 27 | return date; 28 | } 29 | 30 | public void setDate(String date) { 31 | this.date = date; 32 | } 33 | 34 | public String getHigh() { 35 | return high; 36 | } 37 | 38 | public void setHigh(String high) { 39 | this.high = high; 40 | } 41 | 42 | public String getFx() { 43 | return fx; 44 | } 45 | 46 | public void setFx(String fx) { 47 | this.fx = fx; 48 | } 49 | 50 | public String getLow() { 51 | return low; 52 | } 53 | 54 | public void setLow(String low) { 55 | this.low = low; 56 | } 57 | 58 | public String getFl() { 59 | return fl; 60 | } 61 | 62 | public void setFl(String fl) { 63 | this.fl = fl; 64 | } 65 | 66 | public String getType() { 67 | return type; 68 | } 69 | 70 | public void setType(String type) { 71 | this.type = type; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-redis/src/main/resources/application.properties -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /samples/micro-weather-redis/src/test/java/com/waylau/spring/cloud/service/WeatherDataServiceTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud.service; 2 | 3 | import org.junit.Test; 4 | 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | import com.waylau.spring.cloud.vo.WeatherResponse; 11 | /** 12 | * 天气服务测试. 13 | * 14 | * @since 1.0.0 2017年9月4日 15 | * @author Way Lau 16 | */ 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest 19 | public class WeatherDataServiceTests { 20 | 21 | @Autowired 22 | private WeatherDataService weatherDataService; 23 | 24 | @Test 25 | public void testGetDataByCityId() { 26 | WeatherResponse response = weatherDataService.getDataByCityId("101280601"); 27 | System.out.println(response.getDesc()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /samples/micro-weather-zuul/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | /bin/ 27 | -------------------------------------------------------------------------------- /samples/micro-weather-zuul/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.0.0.M3' 4 | } 5 | repositories { 6 | //mavenCentral() 7 | maven { url "https://repo.spring.io/snapshot" } 8 | maven { url "https://repo.spring.io/milestone" } 9 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 10 | } 11 | dependencies { 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'eclipse' 18 | apply plugin: 'org.springframework.boot' 19 | apply plugin: 'io.spring.dependency-management' 20 | 21 | version = '1.0.0' 22 | sourceCompatibility = 1.8 23 | 24 | repositories { 25 | //mavenCentral() 26 | maven { url "https://repo.spring.io/snapshot" } 27 | maven { url "https://repo.spring.io/milestone" } 28 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 29 | } 30 | 31 | ext { 32 | springCloudVersion = 'Finchley.M2' 33 | } 34 | 35 | dependencies { 36 | compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') 37 | compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul') 38 | testCompile('org.springframework.boot:spring-boot-starter-test') 39 | } 40 | 41 | dependencyManagement { 42 | imports { 43 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /samples/micro-weather-zuul/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waylau/spring-cloud-tutorial/ee98841d2e4a398dcd6e3f639589022b83e8dfb2/samples/micro-weather-zuul/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/micro-weather-zuul/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | distributionUrl=file\:/D:/software/webdev/java/gradle-4.0-all.zip 7 | -------------------------------------------------------------------------------- /samples/micro-weather-zuul/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /samples/micro-weather-zuul/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /samples/micro-weather-zuul/src/main/java/com/waylau/spring/cloud/Application.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableZuulProxy 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /samples/micro-weather-zuul/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name: micro-weather-zuul 2 | 3 | eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/ 4 | 5 | zuul.routes.users.path: /hi/** 6 | zuul.routes.users.serviceId: micro-weather-eureka-client -------------------------------------------------------------------------------- /samples/micro-weather-zuul/src/test/java/com/waylau/spring/cloud/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.waylau.spring.cloud; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------