├── config-client-consumer
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzf
│ │ └── config
│ │ └── consumer
│ │ ├── ConfigClientConsumerApplication.java
│ │ ├── config
│ │ └── AuthorConfig.java
│ │ └── controller
│ │ └── ConfigConsumerController.java
│ └── resources
│ ├── application.yml
│ └── bootstrap.yml
├── config-server
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzf
│ │ └── config
│ │ └── ConfigServerApplication.java
│ └── resources
│ └── application.yml
├── eureka-client-consumer
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzf
│ │ └── consumer
│ │ ├── ConsumerApplication.java
│ │ ├── controller
│ │ └── CompanyController.java
│ │ ├── hystrix
│ │ └── HystrixClientConfigration.java
│ │ └── rest
│ │ ├── HystrixClientRemoteInterface.java
│ │ └── RemoteInterface.java
│ └── resources
│ └── application.yml
├── eureka-client-provider
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzf
│ │ └── provider
│ │ ├── ProviderApplication.java
│ │ └── controller
│ │ └── CompanyProviderController.java
│ └── resources
│ └── application.yml
├── eureka-server
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzf
│ │ └── eureka
│ │ └── EurekaApplication.java
│ └── resources
│ └── application.yml
├── gateway
└── pom.xml
├── pom.xml
├── zuul-service-using-config
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── zzf
│ │ └── zuul
│ │ ├── ZuulServiceApplication.java
│ │ ├── config
│ │ └── SecurityConfiguration.java
│ │ └── filter
│ │ └── SimpleFilter.java
│ └── resources
│ ├── application.properties
│ ├── application.yml
│ └── bootstrap.yml
└── zuul-service
├── pom.xml
└── src
└── main
├── java
└── com
│ └── zzf
│ └── zuul
│ └── ZuulServiceApplication.java
└── resources
└── application.yml
/config-client-consumer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | config-client-consumer
13 |
14 |
15 |
16 | org.springframework.cloud
17 | spring-cloud-starter-config
18 |
19 |
20 |
21 | org.springframework.cloud
22 | spring-cloud-starter-netflix-eureka-client
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-web
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-maven-plugin
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/config-client-consumer/src/main/java/com/zzf/config/consumer/ConfigClientConsumerApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.config.consumer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | /**
8 | * Created with IntelliJ IDEA.
9 | *
10 | * @author: zzf
11 | * @date: 2018/3/5
12 | * @time: 19:30
13 | * @description : do some thing
14 | */
15 | @SpringBootApplication
16 | @EnableDiscoveryClient
17 | public class ConfigClientConsumerApplication {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(ConfigClientConsumerApplication.class, args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/config-client-consumer/src/main/java/com/zzf/config/consumer/config/AuthorConfig.java:
--------------------------------------------------------------------------------
1 | package com.zzf.config.consumer.config;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.PropertySource;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * Created with IntelliJ IDEA.
10 | *
11 | * @author: zzf
12 | * @date: 2018/3/5
13 | * @time: 21:16
14 | * @description : do some thing
15 | */
16 | @Component
17 | @ConfigurationProperties(prefix = "spring.zzf")
18 | public class AuthorConfig {
19 |
20 | private String name;
21 | private Integer age;
22 | private Integer sex;
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public Integer getAge() {
33 | return age;
34 | }
35 |
36 | public void setAge(Integer age) {
37 | this.age = age;
38 | }
39 |
40 | public Integer getSex() {
41 | return sex;
42 | }
43 |
44 | public void setSex(Integer sex) {
45 | this.sex = sex;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "AuthorConfig{" +
51 | "name='" + name + '\'' +
52 | ", age=" + age +
53 | ", sex=" + sex +
54 | '}';
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/config-client-consumer/src/main/java/com/zzf/config/consumer/controller/ConfigConsumerController.java:
--------------------------------------------------------------------------------
1 | package com.zzf.config.consumer.controller;
2 |
3 | import com.zzf.config.consumer.config.AuthorConfig;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 |
9 | /**
10 | * Created with IntelliJ IDEA.
11 | *
12 | * @author: zzf
13 | * @date: 2018/3/5
14 | * @time: 21:30
15 | * @description : do some thing
16 | */
17 | @Controller
18 | @RequestMapping("configConsumer")
19 | public class ConfigConsumerController {
20 |
21 | @Autowired
22 | private AuthorConfig authorConfig;
23 |
24 | @RequestMapping("/getAuthorInfo")
25 | @ResponseBody
26 | public String getAuthorInfo(){
27 |
28 | return " author信息是丛git上加载下来的 :" + authorConfig.toString();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/config-client-consumer/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: config-client-consumer
4 | server:
5 | port: 9093
6 |
7 |
--------------------------------------------------------------------------------
/config-client-consumer/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | label: master
5 | uri: http://localhost:9092
6 | name: author,config-info,default
7 |
8 | # 需要注意的是, author 就是git 上配置的文件名称
--------------------------------------------------------------------------------
/config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | config-server
13 |
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-config-server
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-actuator
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-maven-plugin
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/config-server/src/main/java/com/zzf/config/ConfigServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.config;
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 | * Created with IntelliJ IDEA.
9 | *
10 | * @author: zzf
11 | * @date: 2018/3/5
12 | * @time: 17:38
13 | * @description : do some thing
14 | */
15 | @EnableConfigServer
16 | @SpringBootApplication
17 | public class ConfigServerApplication {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(ConfigServerApplication.class, args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/config-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | server:
5 | git:
6 | uri: https://gitee.com/zhongzunfa/spring-cloud-config.git
7 | search-paths: V1-DEV
8 |
9 | application:
10 | name: config-server
11 |
12 | server:
13 | port: 9092 #启动端口
--------------------------------------------------------------------------------
/eureka-client-consumer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | eureka-client-consumer
13 |
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-netflix-eureka-client
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-openfeign
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-netflix-hystrix
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-web
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/eureka-client-consumer/src/main/java/com/zzf/consumer/ConsumerApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.consumer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
8 | import org.springframework.cloud.openfeign.EnableFeignClients;
9 |
10 | /**
11 | * Created with IntelliJ IDEA.
12 | *
13 | * @author: zzf
14 | * @date: 2018/3/4
15 | * @time: 13:46
16 | * @description : 这里包含, Eureka 客户端发现, 熔断, 远程调用, 客户端负载等
17 | */
18 | @SpringBootApplication
19 | @EnableDiscoveryClient
20 | @EnableCircuitBreaker
21 | @EnableFeignClients
22 | public class ConsumerApplication {
23 |
24 | public static void main(String[] args) {
25 | SpringApplication.run(ConsumerApplication.class, args);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/eureka-client-consumer/src/main/java/com/zzf/consumer/controller/CompanyController.java:
--------------------------------------------------------------------------------
1 | package com.zzf.consumer.controller;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.zzf.consumer.rest.HystrixClientRemoteInterface;
5 | import com.zzf.consumer.rest.RemoteInterface;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Controller;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestMethod;
10 | import org.springframework.web.bind.annotation.ResponseBody;
11 | import org.springframework.web.bind.annotation.RestController;
12 |
13 | /**
14 | * Created with IntelliJ IDEA.
15 | *
16 | * @author: zzf
17 | * @date: 2018/3/4
18 | * @time: 14:05
19 | * @description : do some thing
20 | */
21 |
22 | @Controller
23 | @RequestMapping("company")
24 | public class CompanyController {
25 |
26 | @Autowired
27 | private RemoteInterface remoteInterface;
28 |
29 | @Autowired
30 | private HystrixClientRemoteInterface hystrixClientRemoteInterface;
31 |
32 | /**
33 | * 容错方法在接口实现类中
34 | * @param teamName
35 | * @return
36 | */
37 | @RequestMapping(value = "/teamInfo", method = RequestMethod.GET)
38 | @ResponseBody
39 | public String getTeamInfo(String teamName){
40 | return hystrixClientRemoteInterface.getTeamInfo(teamName);
41 | }
42 |
43 | @HystrixCommand(fallbackMethod = "getCompanyInfoFallback")
44 | @RequestMapping(value = "/companyInfo", method = RequestMethod.GET)
45 | @ResponseBody
46 | public String getCompanyInfo(String companyName){
47 |
48 | return remoteInterface.getCompanyInfoByProvider(companyName);
49 | }
50 |
51 | /**
52 | * 主要注意的是: 容错的方法, 参数要与请求的一致。
53 | * 容错返回的方法
54 | * @return
55 | */
56 | public String getCompanyInfoFallback(String companyName){
57 | return "this is fallBack, company name is " + companyName;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/eureka-client-consumer/src/main/java/com/zzf/consumer/hystrix/HystrixClientConfigration.java:
--------------------------------------------------------------------------------
1 | package com.zzf.consumer.hystrix;
2 |
3 | import com.zzf.consumer.rest.HystrixClientRemoteInterface;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/3/5
10 | * @time: 15:10
11 | * @description : 类执行的容错。
12 | */
13 | public class HystrixClientConfigration implements HystrixClientRemoteInterface {
14 |
15 | @Override
16 | public String getTeamInfo(String teamName) {
17 |
18 | return "获取" + teamName + "失败。";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/eureka-client-consumer/src/main/java/com/zzf/consumer/rest/HystrixClientRemoteInterface.java:
--------------------------------------------------------------------------------
1 | package com.zzf.consumer.rest;
2 |
3 | import com.zzf.consumer.hystrix.HystrixClientConfigration;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 |
9 | /**
10 | * Created with IntelliJ IDEA.
11 | *
12 | * @author: zzf
13 | * @date: 2018/3/5
14 | * @time: 13:32
15 | * @description : 远程调用, 使用类作的方法作为容错的方法
16 | */
17 | @FeignClient(name = "eureka-client-provider", configuration = HystrixClientConfigration.class)
18 | public interface HystrixClientRemoteInterface {
19 |
20 | @RequestMapping(value = "/getTeamInfo", method = RequestMethod.GET)
21 | public String getTeamInfo(@RequestParam("teamName") String teamName);
22 | }
23 |
--------------------------------------------------------------------------------
/eureka-client-consumer/src/main/java/com/zzf/consumer/rest/RemoteInterface.java:
--------------------------------------------------------------------------------
1 | package com.zzf.consumer.rest;
2 |
3 | import org.springframework.cloud.openfeign.FeignClient;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 |
9 | /**
10 | * Created with IntelliJ IDEA.
11 | *
12 | * @author: zzf
13 | * @date: 2018/3/4
14 | * @time: 23:16
15 | * @description : 远程调用接口
16 | */
17 | @FeignClient("eureka-client-provider")
18 | public interface RemoteInterface {
19 |
20 | /**
21 | * 获取公司信息
22 | * @param companyName
23 | * @return
24 | */
25 | @RequestMapping(value = "/getCompanyInfoByProvider", method = RequestMethod.GET)
26 | public String getCompanyInfoByProvider(@RequestParam("companyName") String companyName);
27 | }
28 |
--------------------------------------------------------------------------------
/eureka-client-consumer/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: eureka-client-consumer
4 |
5 | eureka:
6 | client:
7 | service-url:
8 | defaultZone: http://localhost:9871/eureka
9 | server:
10 | port: 9091
11 |
12 |
--------------------------------------------------------------------------------
/eureka-client-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | eureka-client-provider
13 |
14 |
15 |
16 |
17 |
18 | org.springframework.cloud
19 | spring-cloud-starter-netflix-eureka-client
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-web
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-maven-plugin
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/eureka-client-provider/src/main/java/com/zzf/provider/ProviderApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.provider;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | /**
8 | * Created with IntelliJ IDEA.
9 | *
10 | * @author: zzf
11 | * @date: 2018/3/5
12 | * @time: 0:52
13 | * @description : do some thing
14 | */
15 | @SpringBootApplication
16 | @EnableDiscoveryClient
17 | public class ProviderApplication {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(ProviderApplication.class, args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/eureka-client-provider/src/main/java/com/zzf/provider/controller/CompanyProviderController.java:
--------------------------------------------------------------------------------
1 | package com.zzf.provider.controller;
2 |
3 | import org.springframework.web.bind.annotation.*;
4 |
5 | /**
6 | * Created with IntelliJ IDEA.
7 | *
8 | * @author: zzf
9 | * @date: 2018/3/5
10 | * @time: 1:08
11 | * @description : do some thing
12 | */
13 | @RestController
14 | public class CompanyProviderController {
15 |
16 | @RequestMapping(value = "/getCompanyInfoByProvider", method = RequestMethod.GET)
17 | @ResponseBody
18 | public String getCompanyInfoByProvider(@RequestParam("companyName") String companyName){
19 |
20 | // 这里是要和数据库交互, 这里为了操作简单直接返回一个数据。
21 | return "provider 查询" + companyName + "公司信息";
22 | }
23 |
24 | @RequestMapping(value = "/getTeamInfo", method = RequestMethod.GET)
25 | @ResponseBody
26 | public String getTeamInfo(@RequestParam("teamName") String teamName){
27 |
28 | // 返回团队信息。
29 | return "provider 查询" + teamName + "团队信息";
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/eureka-client-provider/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 |
2 | spring:
3 | application:
4 | name: eureka-client-provider
5 |
6 | eureka:
7 | client:
8 | service-url:
9 | defaultZone: http://localhost:9871/eureka
10 |
11 | server:
12 | port: 9090
13 |
--------------------------------------------------------------------------------
/eureka-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 | eureka-server
12 |
13 |
14 |
15 | org.springframework.cloud
16 | spring-cloud-starter-netflix-eureka-server
17 |
18 |
19 |
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-maven-plugin
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/eureka-server/src/main/java/com/zzf/eureka/EurekaApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.eureka;
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 | /**
8 | * Created with IntelliJ IDEA.
9 | *
10 | * @author: zzf
11 | * @date: 2018/3/3
12 | * @time: 13:27
13 | * @description : eureka 服务
14 | */
15 | @SpringBootApplication
16 | @EnableEurekaServer
17 | public class EurekaApplication {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(EurekaApplication.class, args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/eureka-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 9871
3 |
4 | eureka:
5 | instance:
6 | hostname: localhost
7 | client:
8 | registerWithEureka: false
9 | fetchRegistry: false
10 | serviceUrl:
11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
--------------------------------------------------------------------------------
/gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | gateway
13 |
14 |
15 |
16 | org.springframework.cloud
17 | spring-cloud-starter-gateway
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-actuator
23 |
24 |
25 |
26 |
27 | spring-milestones
28 | Spring Milestones
29 | https://repo.spring.io/libs-milestone
30 |
31 | false
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.zzf.springcloud
8 | zzf-spring-cloud-Finchley
9 | pom
10 | 1.0-SNAPSHOT
11 |
12 | eureka-server
13 | eureka-client-consumer
14 | eureka-client-provider
15 | config-server
16 | config-client-consumer
17 | zuul-service
18 | zuul-service-using-config
19 | gateway
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-parent
25 | 2.0.0.RELEASE
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.springframework.cloud
33 | spring-cloud-dependencies
34 | Finchley.M7
35 | pom
36 | import
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | spring-milestones
45 | Spring Milestones
46 | https://repo.spring.io/libs-milestone
47 |
48 | false
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-maven-plugin
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/zuul-service-using-config/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | zuul-service-using-config
13 |
14 |
15 |
16 | org.springframework.cloud
17 | spring-cloud-starter-netflix-zuul
18 |
19 |
20 |
21 | org.springframework.cloud
22 | spring-cloud-starter-netflix-eureka-client
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-actuator
28 |
29 |
30 |
31 | org.springframework.cloud
32 | spring-cloud-starter-config
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-security
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/zuul-service-using-config/src/main/java/com/zzf/zuul/ZuulServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.zuul;
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 | /**
9 | * Created with IntelliJ IDEA.
10 | *
11 | * @author: zzf
12 | * @date: 2018/3/6
13 | * @time: 10:43
14 | * @description : zuul 服务
15 | */
16 | @SpringBootApplication
17 | @EnableDiscoveryClient
18 | @EnableZuulProxy
19 | public class ZuulServiceApplication {
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(ZuulServiceApplication.class, args);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/zuul-service-using-config/src/main/java/com/zzf/zuul/config/SecurityConfiguration.java:
--------------------------------------------------------------------------------
1 |
2 | package com.zzf.zuul.config;
3 |
4 | import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 | import org.springframework.security.core.userdetails.User;
10 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
11 |
12 |
13 | @Configuration
14 | public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
15 |
16 | @SuppressWarnings("deprecation")
17 | @Bean
18 | public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
19 | return new InMemoryUserDetailsManager(
20 | User.withDefaultPasswordEncoder().username("user").password("password")
21 | .authorities("ROLE_USER").build(),
22 | User.withDefaultPasswordEncoder().username("admin").password("admin")
23 | .authorities("ROLE_ACTUATOR", "ROLE_USER").build());
24 | }
25 |
26 | @Override
27 | protected void configure(HttpSecurity http) throws Exception {
28 | // @formatter:off
29 | http
30 | .authorizeRequests()
31 | .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ACTUATOR")
32 | .antMatchers("/**").permitAll()
33 | .and()
34 | .httpBasic();
35 | // @formatter:on
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/zuul-service-using-config/src/main/java/com/zzf/zuul/filter/SimpleFilter.java:
--------------------------------------------------------------------------------
1 | package com.zzf.zuul.filter;
2 |
3 | /**
4 | * Created with IntelliJ IDEA.
5 | *
6 | * @author: zzf
7 | * @date: 2018/3/8
8 | * @time: 10:24
9 | * @description : do some thing
10 | */
11 | public class SimpleFilter {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/zuul-service-using-config/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | management.endpoints.web.exposure.include=*
2 | #management.endpoint.shutdown.enabled=true
3 | management.endpoint.health.show-details=always
--------------------------------------------------------------------------------
/zuul-service-using-config/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: zuul-service
4 | server:
5 | port: 9095
6 |
7 | zuul:
8 | prefix: /api #为zuul设置一个公共的前缀
9 | routes:
10 | consumer:
11 | path: /consumer/**
12 | serviceId: eureka-client-consumer
13 | configConsumer:
14 | path: /configConsumer/**
15 | serviceId: config-client-consumer
16 |
--------------------------------------------------------------------------------
/zuul-service-using-config/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | cloud:
3 | config:
4 | label: master
5 | uri: http://localhost:9092
6 | name: zuul-config,default
7 |
8 | # 需要注意的是 name : 后面的是是git 上面的文件名称
--------------------------------------------------------------------------------
/zuul-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | zzf-spring-cloud-Finchley
7 | com.zzf.springcloud
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | zuul-service
13 |
14 |
15 |
16 | org.springframework.cloud
17 | spring-cloud-starter-netflix-zuul
18 |
19 |
20 |
21 | org.springframework.cloud
22 | spring-cloud-starter-netflix-eureka-client
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-actuator
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-maven-plugin
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/zuul-service/src/main/java/com/zzf/zuul/ZuulServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.zzf.zuul;
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 | /**
9 | * Created with IntelliJ IDEA.
10 | *
11 | * @author: zzf
12 | * @date: 2018/3/6
13 | * @time: 10:43
14 | * @description : zuul 服务
15 | */
16 | @SpringBootApplication
17 | @EnableDiscoveryClient
18 | @EnableZuulProxy
19 | public class ZuulServiceApplication {
20 |
21 | public static void main(String[] args) {
22 | SpringApplication.run(ZuulServiceApplication.class, args);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/zuul-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: zuul-service
4 | server:
5 | port: 9094
6 |
7 | zuul:
8 | prefix: /api #为zuul设置一个公共的前缀
9 | routes:
10 | consumer:
11 | path: /consumer/**
12 | serviceId: eureka-client-consumer
13 | configConsumer:
14 | path: /configConsumer/**
15 | serviceId: config-client-consumer
16 |
17 | eureka:
18 | client:
19 | service-url:
20 | defaultZone: http://localhost:9871/eureka
21 |
22 |
--------------------------------------------------------------------------------