├── oAuth2
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── OAuth2Application.java
└── pom.xml
├── security
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── SecurityApplication.java
└── pom.xml
├── README.md
├── admin
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── AdminApplication.java
└── pom.xml
├── eureka
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── EurekaApplication.java
└── pom.xml
├── hystrix
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ ├── service
│ │ ├── HystrixFeignServiceImpl.java
│ │ └── HystrixFeignService.java
│ │ ├── controller
│ │ ├── HystrixFeignController.java
│ │ └── HystrixRestTemplateController.java
│ │ └── HystrixApplication.java
└── pom.xml
├── provider
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ ├── ProviderApplication.java
│ │ └── controller
│ │ └── ProviderController.java
└── pom.xml
├── config-bus
├── src
│ └── main
│ │ ├── resources
│ │ ├── bootstrap.properties
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── BusApplication.java
└── pom.xml
├── config-client
├── src
│ └── main
│ │ ├── resources
│ │ ├── bootstrap.properties
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── ConfigClientApplication.java
└── pom.xml
├── config-server
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── ConfigServerApplication.java
└── pom.xml
├── zuul
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ ├── ZuulApplication.java
│ │ ├── controller
│ │ └── MyErrorController.java
│ │ └── MyZuulFilter.java
└── pom.xml
├── consumer
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ ├── ConsumerApplication.java
│ │ ├── service
│ │ └── ConsumerService.java
│ │ └── controller
│ │ └── ConsumerController.java
└── pom.xml
├── sleuth
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── hcmony
│ │ └── SleuthApplication.java
└── pom.xml
├── pom.xml
└── springcloud-hotchpotch
├── gateway
└── gateway.iml
└── bus
└── bus.iml
/oAuth2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/security/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # springcloud 学习教程,基于springboot2.0的Finchley.SR2 版本已经全部更新完成
2 |
--------------------------------------------------------------------------------
/admin/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hcmony/SpringCloud/HEAD/admin/src/main/resources/application.properties
--------------------------------------------------------------------------------
/eureka/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hcmony/SpringCloud/HEAD/eureka/src/main/resources/application.properties
--------------------------------------------------------------------------------
/hystrix/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hcmony/SpringCloud/HEAD/hystrix/src/main/resources/application.properties
--------------------------------------------------------------------------------
/provider/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hcmony/SpringCloud/HEAD/provider/src/main/resources/application.properties
--------------------------------------------------------------------------------
/config-bus/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=config-bus
2 | spring.cloud.config.label=master
3 | spring.cloud.config.profile=dev
4 | spring.cloud.config.uri=http://localhost:8095/
5 | server.port=8097
6 |
7 | eureka.client.service-url.defaultZone= http://localhost:8888/eureka/
--------------------------------------------------------------------------------
/config-client/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=config-client
2 | spring.cloud.config.label=master
3 | spring.cloud.config.profile=dev
4 | spring.cloud.config.uri=http://localhost:8095/
5 | server.port=8096
6 |
7 | eureka.client.service-url.defaultZone= http://localhost:8888/eureka/
--------------------------------------------------------------------------------
/config-bus/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.rabbitmq.host=localhost
2 | spring.rabbitmq.port=5672
3 | spring.rabbitmq.username=guest
4 | spring.rabbitmq.password=guest
5 |
6 | spring.cloud.bus.enabled=true
7 | spring.cloud.bus.trace.enabled=true
8 | management.endpoints.web.exposure.include=bus-refresh
--------------------------------------------------------------------------------
/config-client/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.rabbitmq.host=localhost
2 | spring.rabbitmq.port=5672
3 | spring.rabbitmq.username=guest
4 | spring.rabbitmq.password=guest
5 |
6 | spring.cloud.bus.enabled=true
7 | spring.cloud.bus.trace.enabled=true
8 | management.endpoints.web.exposure.include=bus-refresh
--------------------------------------------------------------------------------
/oAuth2/src/main/java/com/hcmony/OAuth2Application.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class OAuth2Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(OAuth2Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/security/src/main/java/com/hcmony/SecurityApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SecurityApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SecurityApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/config-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=config-server
2 | server.port=8095
3 |
4 | eureka.client.service-url.defaultZone= http://localhost:8888/eureka/
5 |
6 | spring.cloud.config.server.git.uri=https://github.com/hcmony/config
7 | spring.cloud.config.server.git.searchPaths=dev
8 | spring.cloud.config.label=master
9 | spring.cloud.config.server.git.username=
10 | spring.cloud.config.server.git.password=
11 |
--------------------------------------------------------------------------------
/hystrix/src/main/java/com/hcmony/service/HystrixFeignServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.service;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | /**
6 | *
Shenjue.java基本描述
7 | *
8 | *
9 | * @author com.hcmony
10 | * @since V1.0.0, 2019/03/04 16:52
11 | */
12 | @Component
13 | public class HystrixFeignServiceImpl implements HystrixFeignService {
14 |
15 | @Override
16 | public String test(String s) {
17 | return "error"+s;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/zuul/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8094
2 | eureka.instance.ip-address=true
3 | eureka.client.service-url.defaultZone= http://10.10.1.37:8888/eureka/
4 | spring.application.name=zuul
5 | spring.zipkin.base-url=http://10.10.1.37:9411
6 | spring.sleuth.sampler.percentage =1.0
7 |
8 | zuul.routes.provider.path=/provider/**
9 | zuul.routes.provider.serviceId=provider
10 |
11 | zuul.routes.consumer.path=/consumer/**
12 | zuul.routes.consumer.serviceId=consumer
13 |
--------------------------------------------------------------------------------
/zuul/src/main/java/com/hcmony/ZuulApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
6 |
7 |
8 | @EnableZuulProxy
9 | @SpringBootApplication
10 | public class ZuulApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(ZuulApplication.class, args);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/eureka/src/main/java/com/hcmony/EurekaApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
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 | @EnableEurekaServer
8 | @SpringBootApplication
9 | public class EurekaApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(EurekaApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/provider/src/main/java/com/hcmony/ProviderApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | @EnableDiscoveryClient
8 | @SpringBootApplication
9 | public class ProviderApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ProviderApplication.class, args);
13 | }
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/config-server/src/main/java/com/hcmony/ConfigServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 |
8 | @EnableConfigServer
9 | @SpringBootApplication
10 | public class ConfigServerApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(ConfigServerApplication.class, args);
14 | }
15 |
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/provider/src/main/java/com/hcmony/controller/ProviderController.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Shenjue.java基本描述
8 | *
9 | *
10 | * @author hcmony
11 | * @since V1.0.0, 2019/03/04 16:52
12 | */
13 | @RestController
14 | public class ProviderController {
15 |
16 | @RequestMapping("test")
17 | public String test(String s){
18 | return s;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/consumer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8092
2 | eureka.client.service-url.defaultZone= http://10.10.1.37:8888/eureka/
3 | spring.application.name=consumer
4 | eureka.instance.preferIpAddress=true
5 | eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
6 |
7 | spring.zipkin.base-url=http://localhost:8200
8 |
9 | #��¶actuator�����ж˵�
10 | management.endpoints.web.exposure.include=*
11 | ##health endpoint�Ƿ������ʾȫ��ϸ�ڡ�Ĭ�������, /actuator/health �ǹ����ģ����Ҳ���ʾϸ��
12 | management.endpoint.health.show-details=always
13 |
--------------------------------------------------------------------------------
/admin/src/main/java/com/hcmony/AdminApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 |
4 | import de.codecentric.boot.admin.server.config.EnableAdminServer;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8 |
9 | @EnableAdminServer
10 | @SpringBootApplication
11 | @EnableDiscoveryClient
12 | public class AdminApplication {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(AdminApplication.class, args);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/consumer/src/main/java/com/hcmony/ConsumerApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
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.openfeign.EnableFeignClients;
7 |
8 | @EnableFeignClients
9 | @EnableDiscoveryClient
10 | @SpringBootApplication
11 | public class ConsumerApplication {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(ConsumerApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/consumer/src/main/java/com/hcmony/service/ConsumerService.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.service;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestParam;
6 |
7 | /**
8 | * Shenjue.java基本描述
9 | *
10 | *
11 | * @author com.hcmony
12 | * @since V1.0.0, 2019/03/04 16:52
13 | */
14 | @FeignClient(value = "provider")
15 | public interface ConsumerService {
16 |
17 | @RequestMapping("/test")
18 | public String test(@RequestParam("s") String s);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/hystrix/src/main/java/com/hcmony/service/HystrixFeignService.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.service;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestParam;
6 |
7 | /**
8 | * Shenjue.java基本描述
9 | *
10 | *
11 | * @author com.hcmony
12 | * @since V1.0.0, 2019/03/04 16:52
13 | */
14 |
15 | @FeignClient(value = "provider",fallback = HystrixFeignServiceImpl.class)
16 | public interface HystrixFeignService {
17 |
18 | @RequestMapping("/test")
19 | public String test(@RequestParam("s") String s);
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/consumer/src/main/java/com/hcmony/controller/ConsumerController.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.controller;
2 |
3 | import com.hcmony.service.ConsumerService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | /**
9 | * Shenjue.java基本描述
10 | *
11 | *
12 | * @author com.hcmony
13 | * @since V1.0.0, 2019/03/04 16:52
14 | */
15 | @RestController
16 | public class ConsumerController {
17 |
18 | @Autowired
19 | private ConsumerService consumerService;
20 |
21 | @RequestMapping("test")
22 | public String test(String s){
23 | return consumerService.test(s);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/eureka/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | eureka
13 | jar
14 |
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-maven-plugin
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/hystrix/src/main/java/com/hcmony/controller/HystrixFeignController.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.controller;
2 |
3 | import com.hcmony.service.HystrixFeignService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | /**
9 | * Shenjue.java基本描述
10 | *
11 | *
12 | * @author com.hcmony
13 | * @since V1.0.0, 2019/03/04 16:52
14 | */
15 | @RestController
16 | public class HystrixFeignController {
17 |
18 | @Autowired
19 | private HystrixFeignService hystrixFeignService;
20 |
21 | @RequestMapping("test")
22 | public String test(String s){
23 | return hystrixFeignService.test(s);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sleuth/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8200
2 | spring.application.name=sleuth
3 | eureka.client.service-url.defaultZone= http://10.10.1.37:8888/eureka/
4 | eureka.instance.preferIpAddress=true
5 | eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
6 |
7 | spring.sleuth.enabled=false
8 |
9 | #��·��ַ
10 | spring.zipkin.base-url=http://10.10.1.37:9411
11 |
12 | #��ص�ַ
13 | spring.boot.admin.client.url=http://10.10.1.37:8070
14 | spring.boot.admin.client.username=root
15 | spring.boot.admin.client.password=root_123
16 | #��¶actuator�����ж˵�
17 | management.endpoints.web.exposure.include=*
18 | #health endpoint�Ƿ������ʾȫ��ϸ�ڡ�Ĭ�������, /actuator/health �ǹ����ģ����Ҳ���ʾϸ��
19 | management.endpoint.health.show-details=always
20 |
21 |
--------------------------------------------------------------------------------
/sleuth/src/main/java/com/hcmony/SleuthApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
6 | import zipkin.server.EnableZipkinServer;
7 |
8 | /**
9 | * 也可直接去下载使用,不用创建服务项目
10 | * 下载地址:https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/
11 | * 也可访问链接: https://pan.baidu.com/s/1eRSy1eHv3XahlAHHbA1kyA 提取码: pkv6 复制这段内容后打开百度网盘手机App,操作更方便哦
12 | */
13 | @SpringBootApplication
14 | @EnableEurekaClient
15 | @EnableZipkinServer
16 | public class SleuthApplication {
17 |
18 | public static void main(String[] args) {
19 | SpringApplication.run(SleuthApplication.class, args);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/config-bus/src/main/java/com/hcmony/BusApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.context.config.annotation.RefreshScope;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @RefreshScope
11 | @RestController
12 | @SpringBootApplication
13 | public class BusApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(BusApplication.class, args);
17 | }
18 |
19 | @Value("${bus}")
20 | private String bus;
21 |
22 | @RequestMapping("/bus")
23 | public String test(){
24 | return bus;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/config-client/src/main/java/com/hcmony/ConfigClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.context.config.annotation.RefreshScope;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @RefreshScope
11 | @RestController
12 | @SpringBootApplication
13 | public class ConfigClientApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(ConfigClientApplication.class, args);
17 | }
18 |
19 | @Value("${test}")
20 | private String test;
21 |
22 | @RequestMapping("/test")
23 | public String test(){
24 | return test;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/hystrix/src/main/java/com/hcmony/HystrixApplication.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
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.hystrix.EnableHystrix;
7 | import org.springframework.cloud.openfeign.EnableFeignClients;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.web.client.RestTemplate;
10 |
11 | @EnableFeignClients
12 | @EnableHystrix
13 | @SpringBootApplication
14 | public class HystrixApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(HystrixApplication.class, args);
18 | }
19 |
20 | /**
21 | * 通过RestTemplate+Ribbon 来实现熔断机制
22 | * @return
23 | */
24 | @LoadBalanced
25 | @Bean
26 | public RestTemplate restTemplate(){
27 | return new RestTemplate();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/consumer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | consumer
13 | jar
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-zipkin
19 |
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-maven-plugin
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/hystrix/src/main/java/com/hcmony/controller/HystrixRestTemplateController.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.controller;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 | import org.springframework.web.client.RestTemplate;
8 |
9 | /**
10 | * Shenjue.java基本描述
11 | *
12 | *
13 | * @author com.hcmony
14 | * @since V1.0.0, 2019/03/04 16:52
15 | */
16 | @RestController
17 | public class HystrixRestTemplateController {
18 |
19 | @Autowired
20 | private RestTemplate restTemplate;
21 |
22 | @HystrixCommand(fallbackMethod = "error")
23 | @RequestMapping("test1")
24 | public String test(String s){
25 | return restTemplate.getForObject("http://provider/test?s="+s,String.class);
26 | }
27 |
28 | public String error(String s){
29 | return "error"+s;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/zuul/src/main/java/com/hcmony/controller/MyErrorController.java:
--------------------------------------------------------------------------------
1 | package com.hcmony.controller;
2 |
3 | import org.springframework.boot.web.servlet.error.ErrorController;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | /**
11 | * 异常信息控制类
12 | *
13 | *
14 | * @author hcmony
15 | * @since V1.0.0, 2019/03/05 10:52
16 | */
17 | @RestController
18 | public class MyErrorController implements ErrorController{
19 | /**
20 | * Returns the path of the error page.
21 | *
22 | * @return the error path
23 | */
24 | @Override
25 | public String getErrorPath() {
26 | return "/error";
27 | }
28 |
29 | @RequestMapping(value = "/error")
30 | public String error(HttpServletResponse resp, HttpServletRequest req) {
31 | return "参数异常或者是其它未知异常";
32 | }
33 |
34 | @RequestMapping(value = "/notoken")
35 | public String notoken(HttpServletResponse resp, HttpServletRequest req) {
36 | return "notoken";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | provider
13 | jar
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-zuul
19 | RELEASE
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-zipkin
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-maven-plugin
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/oAuth2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | oAuth2
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | com.alibaba
24 | fastjson
25 | 1.2.48
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/security/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | security
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | com.alibaba
24 | fastjson
25 | 1.2.48
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | config-server
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-config-server
25 | RELEASE
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/hystrix/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | hystrix
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 |
24 | org.springframework.cloud
25 | spring-cloud-starter-hystrix
26 | RELEASE
27 |
28 |
29 |
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-maven-plugin
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/zuul/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | zuul
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-starter-zuul
25 | RELEASE
26 |
27 |
28 | io.zipkin.brave
29 | brave-spring-beans
30 | 5.5.2
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/config-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | config-client
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-starter-config
25 | RELEASE
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-starter-bus-amqp
30 | RELEASE
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/config-bus/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | config-bus
13 | jar
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | org.springframework.cloud
24 | spring-cloud-starter-config
25 | RELEASE
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-starter-bus-amqp
30 | RELEASE
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/admin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.hcmony
8 | springcloud
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | admin
13 | pom
14 |
15 |
16 | UTF-8
17 | UTF-8
18 | 1.8
19 |
20 |
21 |
22 |
23 | de.codecentric
24 | spring-boot-admin-starter-server
25 | 2.0.6
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/zuul/src/main/java/com/hcmony/MyZuulFilter.java:
--------------------------------------------------------------------------------
1 | package com.hcmony;
2 |
3 |
4 | import com.netflix.zuul.ZuulFilter;
5 | import com.netflix.zuul.context.RequestContext;
6 | import com.netflix.zuul.exception.ZuulException;
7 | import org.apache.commons.lang.StringUtils;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.stereotype.Component;
11 |
12 | import javax.servlet.http.HttpServletRequest;
13 |
14 | /**
15 | * Shenjue.java基本描述
16 | *
17 | *
18 | * @author hcmony
19 | * @since V1.0.0, 2019/03/05 10:04
20 | */
21 | @Component
22 | public class MyZuulFilter extends ZuulFilter {
23 |
24 | private static final Logger LOGGER = LoggerFactory.getLogger(MyZuulFilter.class);
25 | /**
26 | * pre:路由之前
27 | routing:路由之时
28 | post: 路由之后
29 | error:发送错误调用
30 | * @return
31 | */
32 | @Override
33 | public String filterType() {
34 | return "pre";
35 | }
36 |
37 | @Override
38 | public int filterOrder() {
39 | return 0;
40 | }
41 |
42 | @Override
43 | public boolean shouldFilter() {
44 | return true;
45 | }
46 |
47 | @Override
48 | public Object run() throws ZuulException {
49 | RequestContext currentContext = RequestContext.getCurrentContext();
50 | HttpServletRequest request = currentContext.getRequest();
51 | String token = request.getParameter("token");
52 | LOGGER.info("token is {}",token);
53 | if (StringUtils.isNotBlank(token)&&"token".equals(token)){
54 | return null;
55 | }
56 | try {
57 | currentContext.getResponse().sendRedirect("/notoken");
58 | }catch (Exception e){
59 |
60 | }
61 | return null;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/sleuth/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 1.5.6.RELEASE
10 |
11 |
12 | com.hcmony
13 | sleuth
14 | jar
15 |
16 |
17 | UTF-8
18 | UTF-8
19 | 1.8
20 |
21 |
22 |
23 |
24 | com.alibaba
25 | fastjson
26 | 1.2.48
27 |
28 |
29 | io.zipkin.java
30 | zipkin-server
31 | 1.28.0
32 |
33 |
34 | io.zipkin.java
35 | zipkin-autoconfigure-ui
36 | 1.28.0
37 |
38 |
39 | org.springframework.cloud
40 | spring-cloud-starter-eureka
41 | 1.3.6.RELEASE
42 |
43 |
44 |
45 |
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-maven-plugin
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.hcmony
7 | springcloud
8 | pom
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | org.springframework.boot
13 | spring-boot-starter-parent
14 | 2.0.6.RELEASE
15 |
16 |
17 |
18 |
19 | admin
20 | config-server
21 | config-client
22 | consumer
23 | eureka
24 | hystrix
25 | oAuth2
26 | provider
27 | security
28 | sleuth
29 | zuul
30 | config-bus
31 |
32 |
33 |
34 |
35 | nexus-releases
36 | nexus-releases
37 | http://maven.aliyun.com/nexus/content/repositories/releases/
38 |
39 |
40 | nexus-snapshots
41 | nexus-snapshots
42 | http://maven.aliyun.com/nexus/content/repositories/snapshots/
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-dependencies
51 | Finchley.SR2
52 | pom
53 | import
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.cloud
61 | spring-cloud-starter-netflix-eureka-server
62 |
63 |
64 | org.springframework.cloud
65 | spring-cloud-starter-netflix-eureka-client
66 |
67 |
68 | org.springframework.cloud
69 | spring-cloud-starter-openfeign
70 |
71 |
76 |
77 |
78 |
79 | UTF-8
80 | UTF-8
81 | 1.8
82 | 0.0.1-SNAPSHOT
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/springcloud-hotchpotch/gateway/gateway.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/springcloud-hotchpotch/bus/bus.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------