From 55c1d292255b7b4f460b45aea31768f557927236 Mon Sep 17 00:00:00 2001 From: Haotian Zhang <928016560@qq.com> Date: Mon, 4 Jul 2022 16:55:49 +0800 Subject: [PATCH] docs:optimize example (#387) --- CHANGELOG.md | 1 + .../polaris/circuitbreaker/example/ServiceA.java | 3 +-- .../example/ServiceAController.java | 1 - .../polaris/circuitbreaker/example/ServiceB.java | 3 +-- .../example/ServiceBController.java | 12 +----------- .../src/main/resources/bootstrap.yml | 1 - .../polaris/ciruitbreaker/example/ServiceB2.java | 3 +-- .../ciruitbreaker/example/ServiceBController.java | 15 ++++----------- .../src/main/resources/bootstrap.yml | 1 - .../src/main/resources/bootstrap.yml | 2 +- 10 files changed, 10 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4825557c7..1db87dd54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,3 +25,4 @@ - [Refator JacksonUtils and JacksonUtilsTest](https://github.com/Tencent/spring-cloud-tencent/pull/367) - [Feature: support actuator for sct core components](https://github.com/Tencent/spring-cloud-tencent/pull/369) - [docs: Fix javadoc
error](https://github.com/Tencent/spring-cloud-tencent/pull/376) +- [docs:optimize example](https://github.com/Tencent/spring-cloud-tencent/pull/387) diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceA.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceA.java index 1c96db6c9..3db7df8f3 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceA.java +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceA.java @@ -35,7 +35,7 @@ import org.springframework.web.client.RestTemplate; public class ServiceA { public static void main(String[] args) { - SpringApplication.run(ServiceA.class); + SpringApplication.run(ServiceA.class, args); } @Bean @@ -43,5 +43,4 @@ public class ServiceA { public RestTemplate restTemplate() { return new RestTemplate(); } - } diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceAController.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceAController.java index 3ba9901a6..73fc55bd3 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceAController.java +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceAController.java @@ -63,5 +63,4 @@ public class ServiceAController { .getForEntity("http://polaris-circuitbreaker-example-b/example/service/b/info", String.class); return entity.getBody(); } - } diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceB.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceB.java index 7354da537..c8c32bf24 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceB.java +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceB.java @@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class ServiceB { public static void main(String[] args) { - SpringApplication.run(ServiceB.class); + SpringApplication.run(ServiceB.class, args); } - } diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java index 67540c2c9..99b8410d8 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/java/com/tencent/cloud/polaris/circuitbreaker/example/ServiceBController.java @@ -18,7 +18,6 @@ package com.tencent.cloud.polaris.circuitbreaker.example; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -32,21 +31,12 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/example/service/b") public class ServiceBController { - @Value("${is-throw-runtime-exception:#{false}}") - private boolean isThrowRuntimeException; - /** * Get service information. * @return service information */ @GetMapping("/info") public String info() { - if (isThrowRuntimeException) { - throw new RuntimeException("failed for call my service"); - } - else { - return "hello world ! I'm a service B1"; - } + return "hello world ! I'm a service B1"; } - } diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml index 4aba50500..3805dfa5e 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b/src/main/resources/bootstrap.yml @@ -8,4 +8,3 @@ spring: address: grpc://183.47.111.80:8091 namespace: default enabled: true -is-throw-runtime-exception: false diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceB2.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceB2.java index 4aacc0d22..fb6bdc687 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceB2.java +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceB2.java @@ -30,7 +30,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class ServiceB2 { public static void main(String[] args) { - SpringApplication.run(ServiceB2.class); + SpringApplication.run(ServiceB2.class, args); } - } diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceBController.java b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceBController.java index 7e4bb9b4c..83dc45303 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceBController.java +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/java/com/tencent/cloud/polaris/ciruitbreaker/example/ServiceBController.java @@ -18,9 +18,10 @@ package com.tencent.cloud.polaris.ciruitbreaker.example; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; /** @@ -32,21 +33,13 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/example/service/b") public class ServiceBController { - @Value("${is-throw-runtime-exception:#{false}}") - private boolean isThrowRuntimeException; - /** * Get service information. * @return service information */ @GetMapping("/info") + @ResponseStatus(value = HttpStatus.BAD_GATEWAY, reason = "failed for call my service") public String info() { - if (isThrowRuntimeException) { - throw new RuntimeException("failed for call my service"); - } - else { - return "hello world ! I'm a service B2"; - } + return "failed for call service B2"; } - } diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/resources/bootstrap.yml index b150a5424..f3720f09c 100644 --- a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2/src/main/resources/bootstrap.yml @@ -8,4 +8,3 @@ spring: address: grpc://183.47.111.80:8091 namespace: default enabled: true -is-throw-runtime-exception: true diff --git a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml index 84e44d4aa..1f257a787 100644 --- a/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-config-example/src/main/resources/bootstrap.yml @@ -17,4 +17,4 @@ management: web: exposure: include: - - polaris-config \ No newline at end of file + - polaris-config