├── sample_client ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── bootstrap.properties │ │ └── java │ │ │ └── com │ │ │ └── cdy │ │ │ └── sample_client │ │ │ ├── SampleClientApplication.java │ │ │ └── controller │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── com │ │ └── cdy │ │ └── sample_client │ │ └── SampleClientApplicationTests.java ├── .gitignore └── pom.xml ├── sample_client2 ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── bootstrap.properties │ │ └── java │ │ │ └── com │ │ │ └── cdy │ │ │ └── sample_client2 │ │ │ ├── SampleClient2Application.java │ │ │ └── controller │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── com │ │ └── cdy │ │ └── sample_client2 │ │ └── SampleClient2ApplicationTests.java ├── .gitignore └── pom.xml ├── sample_config ├── src │ ├── main │ │ ├── resources │ │ │ ├── properties │ │ │ │ ├── zuul-dev.properties │ │ │ │ ├── client-dev.properties │ │ │ │ └── client2-dev.properties │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── cdy │ │ │ └── sample_config │ │ │ └── SampleConfigApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── cdy │ │ └── sample_config │ │ └── SampleConfigApplicationTests.java ├── .gitignore └── pom.xml ├── .gitignore ├── sample_parent ├── .gitignore └── pom.xml ├── sample_server ├── .gitignore ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── cdy │ │ │ └── sample_server │ │ │ └── SampleServerApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── cdy │ │ └── sample_server │ │ └── SampleServerApplicationTests.java └── pom.xml ├── sample_zuul ├── .gitignore ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── cdy │ │ │ └── sample_zuul │ │ │ └── SampleZuulApplicationTests.java │ └── main │ │ ├── java │ │ └── com │ │ │ └── cdy │ │ │ └── sample_zuul │ │ │ ├── SampleZuulApplication.java │ │ │ └── configuration │ │ │ └── ClientServiceFallbackProvider.java │ │ └── resources │ │ ├── bootstrap.properties │ │ └── application.properties └── pom.xml └── README.md /sample_client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample_client2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sample_config/src/main/resources/properties/zuul-dev.properties: -------------------------------------------------------------------------------- 1 | client2.service.id=client2 2 | client2.port=12001 3 | client.service.id=client 4 | client.port=12000 5 | zuul.service.id=zuul 6 | zuul.port=13000 -------------------------------------------------------------------------------- /sample_config/src/main/resources/properties/client-dev.properties: -------------------------------------------------------------------------------- 1 | client2.service.id=client2 2 | client2.port=12001 3 | client.service.id=client 4 | client.port=12000 5 | zuul.service.id=zuul 6 | zuul.port=13000 -------------------------------------------------------------------------------- /sample_config/src/main/resources/properties/client2-dev.properties: -------------------------------------------------------------------------------- 1 | client2.service.id=client2 2 | client2.port=12001 3 | client.service.id=client 4 | client.port=12000 5 | zuul.service.id=zuul 6 | zuul.port=13000 -------------------------------------------------------------------------------- /.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_client/.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_config/.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_parent/.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_server/.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_zuul/.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_client2/.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 | .sts4-cache 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/ -------------------------------------------------------------------------------- /sample_server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=10000 2 | management.security.enabled=false 3 | #主机名 4 | eureka.instance.hostname=eureka 5 | #是否注册自己 6 | eureka.client.register-with-eureka=false 7 | eureka.client.fetch-registry=false 8 | eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/ 9 | #自我保护模式 10 | eureka.server.enable-self-preservation=false 11 | spring.application.name=eureka-server -------------------------------------------------------------------------------- /sample_client/src/test/java/com/cdy/sample_client/SampleClientApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_client; 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 SampleClientApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /sample_zuul/src/test/java/com/cdy/sample_zuul/SampleZuulApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_zuul; 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 SampleZuulApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /sample_config/src/test/java/com/cdy/sample_config/SampleConfigApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_config; 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 SampleConfigApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /sample_server/src/test/java/com/cdy/sample_server/SampleServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_server; 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 SampleServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /sample_client2/src/test/java/com/cdy/sample_client2/SampleClient2ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_client2; 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 SampleClient2ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #springcloud 简单的脚手架 2 | 3 | #master 主分支主要是eureka+config+zuul 4 | 具体介绍如下的博客 5 | https://blog.csdn.net/cdy1996/article/details/80725271 6 | 7 | 8 | #zookeeper springcloud + zookeeper 使用zookeeper作为注册中心 9 | 10 | https://blog.csdn.net/cdy1996/article/details/80867062 11 | 12 | 13 | #dynamic 主分支的基础上加入zuul的动态路由 + zuul简单认证 14 | 15 | https://blog.csdn.net/cdy1996/article/details/80960215 16 | 17 | #nacos 使用nacos作为服务发现和配置中心 使用最新的springcloud gateway作为网关 18 | 19 | https://blog.csdn.net/cdy1996/article/details/87391609 20 | -------------------------------------------------------------------------------- /sample_zuul/src/main/java/com/cdy/sample_zuul/SampleZuulApplication.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_zuul; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 6 | 7 | @SpringCloudApplication 8 | @EnableZuulProxy 9 | public class SampleZuulApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SampleZuulApplication.class, args); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /sample_config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=11000 2 | #应用名称 3 | spring.application.name=config 4 | #eureka的注册中心 5 | eureka.client.service-url.defaultZone=http://localhost:10000/eureka/ 6 | # 使用ip地址注册到eureka server 7 | eureka.instance.ip-address=true 8 | eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} 9 | #使用本地属性文件 10 | spring.profiles.active=native 11 | #属性文件地址,只要指定文件夹的路径 12 | spring.cloud.config.server.native.searchLocations=classpath:/properties/ 13 | #暂时关闭springsecurity 14 | management.security.enabled=false 15 | -------------------------------------------------------------------------------- /sample_server/src/main/java/com/cdy/sample_server/SampleServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_server; 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 SampleServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SampleServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sample_client/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | server.port=12000 2 | 3 | #spring.cloud.configuration.label=master 4 | spring.application.name=client 5 | #配置面向服务调用 6 | spring.cloud.config.discovery.enabled=true 7 | spring.cloud.config.discovery.service-id=CONFIG 8 | spring.cloud.config.profile: dev 9 | spring.cloud.config.label: master 10 | 11 | management.security.enabled=false 12 | 13 | eureka.client.service-url.defaultZone=http://localhost:10000/eureka/ 14 | # 使用ip地址注册到eureka server 15 | eureka.instance.ip-address=true 16 | eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} 17 | -------------------------------------------------------------------------------- /sample_client2/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | server.port=12001 2 | 3 | #spring.cloud.configuration.label=master 4 | spring.application.name=client2 5 | #配置面向服务调用 6 | spring.cloud.config.discovery.enabled=true 7 | spring.cloud.config.discovery.service-id=CONFIG 8 | spring.cloud.config.profile: dev 9 | spring.cloud.config.label: master 10 | 11 | management.security.enabled=false 12 | 13 | eureka.client.service-url.defaultZone=http://localhost:10000/eureka/ 14 | # 使用ip地址注册到eureka server 15 | eureka.instance.ip-address=true 16 | eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} 17 | -------------------------------------------------------------------------------- /sample_zuul/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | server.port=13000 2 | 3 | #spring.cloud.configuration.label=master 4 | spring.application.name=zuul 5 | #配置面向服务调用 6 | spring.cloud.config.discovery.enabled=true 7 | spring.cloud.config.discovery.service-id=CONFIG 8 | spring.cloud.config.profile: dev 9 | spring.cloud.config.label: master 10 | 11 | management.security.enabled=false 12 | 13 | eureka.client.service-url.defaultZone=http://localhost:10000/eureka/ 14 | # 使用ip地址注册到eureka server 15 | eureka.instance.ip-address=true 16 | eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port} 17 | 18 | -------------------------------------------------------------------------------- /sample_zuul/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #zuul.routes.client.path=/hello 2 | #zuul.routes.client.service-id=${client.service.id} 3 | 4 | #zuul.routes.client2.path=/client2/hello 5 | #zuul.routes.client2.service-id=${client2.service.id} 6 | 7 | #zuul.max.host.connections=500 8 | #zuul.host.connect-timeout-millis=6000 9 | #zuul.host.socket-timeout-millis=6000 10 | 11 | #ribbon超时设置 12 | ribbon.ReadTimeout=1000 13 | ribbon.SocketTimeout=1000 14 | #ribbon.MaxAutoRetries=0 15 | #ribbon.MaxAutoRetriesNextServer=1 16 | 17 | #hystrix超时设置 18 | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 6000 -------------------------------------------------------------------------------- /sample_config/src/main/java/com/cdy/sample_config/SampleConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableConfigServer 10 | @EnableEurekaClient 11 | public class SampleConfigApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SampleConfigApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample_client/src/main/java/com/cdy/sample_client/SampleClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_client; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableEurekaClient 12 | public class SampleClientApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SampleClientApplication.class, args); 16 | } 17 | 18 | @Bean 19 | @LoadBalanced 20 | RestTemplate restTemplate(){ 21 | return new RestTemplate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample_client2/src/main/java/com/cdy/sample_client2/SampleClient2Application.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_client2; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | public class SampleClient2Application { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(SampleClient2Application.class, args); 17 | } 18 | 19 | @Bean 20 | @LoadBalanced 21 | RestTemplate restTemplate(){ 22 | return new RestTemplate(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample_client2/src/main/java/com/cdy/sample_client2/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_client2.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | /** 11 | * todo 12 | * Created by 陈东一 13 | * 2018/6/18 15:49 14 | */ 15 | @RestController 16 | @RefreshScope 17 | public class HelloController { 18 | 19 | @Autowired 20 | private RestTemplate restTemplate; 21 | 22 | @Value("${client.port}") 23 | private String port; 24 | 25 | @Value("${client.service.id}") 26 | private String client; 27 | 28 | @RequestMapping("/hello") 29 | public String hello() { 30 | String body = restTemplate.getForEntity("http://" + client + "/world", String.class).getBody(); 31 | return body; 32 | } 33 | 34 | @RequestMapping("/world") 35 | public String world() { 36 | return client + ":" + port; 37 | } 38 | 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /sample_client/src/main/java/com/cdy/sample_client/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_client.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | /** 13 | * todo 14 | * Created by 陈东一 15 | * 2018/6/18 15:49 16 | */ 17 | @RestController 18 | @RefreshScope 19 | public class HelloController { 20 | 21 | @Autowired 22 | private RestTemplate restTemplate; 23 | 24 | @Value("${client2.port}") 25 | private String port; 26 | 27 | @Value("${client2.service.id}") 28 | private String client; 29 | 30 | @RequestMapping("/hello") 31 | public String hello() { 32 | String body = restTemplate.getForEntity("http://" + client + "/world", String.class).getBody(); 33 | return body; 34 | } 35 | 36 | @RequestMapping("/world") 37 | public String world() { 38 | try { 39 | TimeUnit.SECONDS.sleep(3L); 40 | } catch (InterruptedException e) { 41 | e.printStackTrace(); 42 | } 43 | return client + ":" + port ; 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sample_server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | sample_server 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | sample_server 11 | Demo project for Spring Boot 12 | 13 | 14 | com.cdy 15 | sample_parent 16 | 0.0.1-SNAPSHOT 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-actuator 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sample_config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | sample_config 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | sample_config 11 | Demo project for Spring Boot 12 | 13 | 14 | 15 | 16 | com.cdy 17 | sample_parent 18 | 0.0.1-SNAPSHOT 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-actuator 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-eureka 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-config-server 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /sample_client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | sample_client 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | sample_client 11 | Demo project for Spring Boot 12 | 13 | 14 | com.cdy 15 | sample_parent 16 | 0.0.1-SNAPSHOT 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-actuator 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-ribbon 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-starter-config 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /sample_client2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.cdy 7 | sample_client2 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | sample_client2 12 | Demo project for Spring Boot 13 | 14 | 15 | com.cdy 16 | sample_parent 17 | 0.0.1-SNAPSHOT 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-actuator 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-eureka 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-ribbon 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-starter-config 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /sample_zuul/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.cdy 7 | sample_zuul 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | sample_zuul 12 | Demo project for Spring Boot 13 | 14 | 15 | com.cdy 16 | sample_parent 17 | 0.0.1-SNAPSHOT 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-actuator 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-eureka 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-ribbon 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-starter-config 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-starter-zuul 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /sample_parent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.cdy 7 | sample_parent 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | sample_parent 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.14.RELEASE 18 | 19 | 20 | 21 | 22 | ../sample_client 23 | ../sample_client2 24 | ../sample_zuul 25 | ../sample_server 26 | ../sample_config 27 | 28 | 29 | 30 | UTF-8 31 | UTF-8 32 | 1.8 33 | Edgware.SR3 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-dependencies 43 | ${spring-cloud.version} 44 | pom 45 | import 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /sample_zuul/src/main/java/com/cdy/sample_zuul/configuration/ClientServiceFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package com.cdy.sample_zuul.configuration; 2 | 3 | import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; 4 | import org.springframework.http.HttpHeaders; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.client.ClientHttpResponse; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.nio.charset.Charset; 14 | 15 | /** 16 | * todo 17 | * Created by 陈东一 18 | * 2018/6/23 10:41 19 | */ 20 | //@Component 21 | public class ClientServiceFallbackProvider implements FallbackProvider { 22 | 23 | @Override 24 | public ClientHttpResponse fallbackResponse(Throwable cause) { 25 | if (cause != null && cause.getCause() != null) { 26 | String reason = cause.getCause().getMessage(); 27 | System.err.printf("Excption %s", reason); 28 | System.out.println(); 29 | } 30 | return fallbackResponse(); 31 | } 32 | 33 | @Override 34 | public String getRoute() { 35 | return "client"; 36 | } 37 | 38 | @Override 39 | public ClientHttpResponse fallbackResponse() { 40 | return new ClientHttpResponse() { 41 | @Override 42 | public HttpStatus getStatusCode() throws IOException { 43 | return HttpStatus.OK; 44 | } 45 | 46 | @Override 47 | public int getRawStatusCode() throws IOException { 48 | return this.getStatusCode().value(); 49 | } 50 | 51 | @Override 52 | public String getStatusText() throws IOException { 53 | return this.getStatusCode().getReasonPhrase(); 54 | } 55 | 56 | @Override 57 | public void close() { 58 | 59 | } 60 | 61 | @Override 62 | public InputStream getBody() throws IOException { 63 | return new ByteArrayInputStream("client不可用".getBytes()); 64 | } 65 | 66 | @Override 67 | public HttpHeaders getHeaders() { 68 | HttpHeaders headers = new HttpHeaders(); 69 | MediaType mt = new MediaType("application", "json", Charset.forName("UTF-8")); 70 | headers.setContentType(mt); 71 | return headers; 72 | } 73 | }; 74 | } 75 | } 76 | --------------------------------------------------------------------------------