From e096d4496afba6031710d39663bdc78937309742 Mon Sep 17 00:00:00 2001 From: SkyeBeFreeman <928016560@qq.com> Date: Wed, 15 Sep 2021 20:10:17 +0800 Subject: [PATCH] fix:fix context configuration NPE when using standalone polaris --- README-zh.md | 4 ++++ README.md | 6 +++++- pom.xml | 2 +- spring-cloud-tencent-dependencies/pom.xml | 4 ++-- .../spring-cloud-tencent-polaris-discovery.md | 11 +++++++++++ .../spring-cloud-tencent-polaris-circuitbreaker.md | 2 +- .../doc/spring-cloud-tencent-polaris-discovery.md | 13 ++++++++++++- .../doc/spring-cloud-tencent-polaris-gateway.md | 2 +- .../doc/spring-cloud-tencent-polaris-ratelimit.md | 2 +- .../src/main/resources/{conf => }/polaris.yml | 0 .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/polaris.yml | 6 ++++++ .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/polaris.yml | 6 ++++++ .../src/main/resources/application.yml | 2 +- .../src/main/resources/application.yml | 2 +- .../src/main/resources/application.yml | 2 +- .../polaris/context/PolarisContextProperties.java | 1 + 18 files changed, 56 insertions(+), 13 deletions(-) rename spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/{conf => }/polaris.yml (100%) create mode 100644 spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml create mode 100644 spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml diff --git a/README-zh.md b/README-zh.md index 8a84ac5c..d1248534 100644 --- a/README-zh.md +++ b/README-zh.md @@ -37,6 +37,8 @@ Spring Cloud Tencent 使用 Maven 来构建,最快的使用方式是将本项 ### 如何引入依赖 在 dependencyManagement 中添加如下配置,然后在 dependencies 中添加自己所需使用的依赖即可使用。 +与此同时,您需要注意Spring Cloud Tencent对应的Spring Cloud版本,进而对应到的Spring Boot版本。 +例如Spring Cloud Tencent的1.0.1.Hoxton.SR9对应Spring Cloud Hoxton版本,需要使用Spring Boot 2.3.x。 ```` @@ -67,6 +69,8 @@ Example 列表: - [Polaris Gateway Example](spring-cloud-tencent-examples/polaris-gateway-example/README-zh.md) +更加详细的使用方法参考 [使用polaris-java](https://github.com/polarismesh/website/blob/main/docs/zh/doc/%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/%E4%BD%BF%E7%94%A8polaris-java.md). + ## 版本号规范 采取与Spring Cloud大版本号相关的版本策略。 diff --git a/README.md b/README.md index bbe512d4..c3ed2e81 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,9 @@ When all the steps are finished, the project will be installed in local Maven re ### How to Introduce Dependency -Add the following configurations n dependencyManagement, then add the dependencies you need. +Add the following configurations in dependencyManagement, then add the dependencies you need. +At the same time, you need to pay attention to the Spring Cloud version corresponding to Spring Cloud Tencent, and then the corresponding Spring Boot version. +For example, Spring Cloud Tencent's 1.0.1.Hoxton.SR9 corresponds to the Spring Cloud Hoxton version and requires Spring Boot 2.3.x. ```` @@ -70,6 +72,8 @@ Example List: - [Polaris Gateway Example](spring-cloud-tencent-examples/polaris-gateway-example/README.md) +For more features, please refer to [使用polaris-java](https://github.com/polarismesh/website/blob/main/docs/zh/doc/%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/%E4%BD%BF%E7%94%A8polaris-java.md). + ### Version Standard We use a version policy related to Spring Cloud's major version number. diff --git a/pom.xml b/pom.xml index a603fceb..243d9f3e 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ - 1.1.1.Hoxton.SR9 + 1.1.2.Hoxton.SR9 Hoxton.SR9 diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 244985e0..35429955 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -62,8 +62,8 @@ - 1.1.1.Hoxton.SR9 - 1.1.1 + 1.1.2.Hoxton.SR9 + 1.2.0 10.0.0-M6 2.0.0 diff --git a/spring-cloud-tencent-docs/src/main/doc-zh/spring-cloud-tencent-polaris-discovery.md b/spring-cloud-tencent-docs/src/main/doc-zh/spring-cloud-tencent-polaris-discovery.md index c201a2ea..4f93ae87 100644 --- a/spring-cloud-tencent-docs/src/main/doc-zh/spring-cloud-tencent-polaris-discovery.md +++ b/spring-cloud-tencent-docs/src/main/doc-zh/spring-cloud-tencent-polaris-discovery.md @@ -47,6 +47,17 @@ spring: address: ${protocol}://${ip}:${port} ``` +3. 如果您部署的是单机版Polaris,您需要在项目中添加如下Polaris参数(.../resources/polaris.yml): + +```yaml +global: + system: + discoverCluster: + sameAsBuiltin: true + healthCheckCluster: + sameAsBuiltin: true +``` + 更加详细的使用方法参考 [Polaris Discovery Example](../../../../spring-cloud-tencent-examples/polaris-discovery-example/README-zh.md)。 ## 拓展使用 diff --git a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-circuitbreaker.md b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-circuitbreaker.md index 3f306c61..c654e4c5 100644 --- a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-circuitbreaker.md +++ b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-circuitbreaker.md @@ -24,7 +24,7 @@ For configuration, please refer to [Polaris CircuitBreaker](https://github.com/p This chapter will explain how to use Polaris in Spring Cloud project in the simplest way. CircuitBreaker's feature. Before starting MicroService, one needs to launch Polaris. Please refer to [Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started). -1. you can add ```spring-cloud-starter-tencent-polaris-circuitbreaker``` 's dependencies in your project to use CircuitBreaker features. For example, in Maven's project, add listed configurations in pom: +1. You can add ```spring-cloud-starter-tencent-polaris-circuitbreaker``` 's dependencies in your project to use CircuitBreaker features. For example, in Maven's project, add listed configurations in pom: ```XML diff --git a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-discovery.md b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-discovery.md index 4aa1381d..7b8eac0c 100644 --- a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-discovery.md +++ b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-discovery.md @@ -24,7 +24,7 @@ CLB supports qualified packet forwarding in the service instance. Through set ba This chapter will explain how to use Polaris Discovery's features in the Spring Cloud project. Before starting MicroService, one needs to launch Polaris. Please refer to [Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started). -1. you can add ```spring-cloud-starter-tencent-polaris-discovery```'s 's dependencies in your project to use Polaris's service registration and discovery feature. For example, in Maven's project, add listed configurations in pom: +1. You can add ```spring-cloud-starter-tencent-polaris-discovery```'s dependencies in your project to use Polaris's service registration and discovery feature. For example, in Maven's project, add listed configurations in pom: ```XML @@ -44,6 +44,17 @@ spring: server-addr: ${ip}:${port} ``` +3. If you deploy standalone Polaris, you should add this polaris configuration in your project(.../resources/polaris.yml): + +```yaml +global: + system: + discoverCluster: + sameAsBuiltin: true + healthCheckCluster: + sameAsBuiltin: true +``` + For further instructions, please refer to [Polaris Discovery Example](../../../../spring-cloud-tencent-examples/polaris-discovery-example/README.md). ## Extended Application diff --git a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-gateway.md b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-gateway.md index f6622969..dce48d79 100644 --- a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-gateway.md +++ b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-gateway.md @@ -22,7 +22,7 @@ This chapter will explain how to use Spring Cloud Tencent Polaris Gateway's feat Before starting MicroService, one needs to launch Polaris. Please refer to [Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started). -1. you can add ```spring-cloud-tencent-polaris-gateway``` in your project to use Polaris's microservice gateway extension features +1. You can add ```spring-cloud-tencent-polaris-gateway``` in your project to use Polaris's microservice gateway extension features (meaning you still need to add microservice gateway modules yourself, such as zuul, spring-cloud-gateway). For example, in Maven's project, add listed configurations in pom: diff --git a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-ratelimit.md b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-ratelimit.md index 39ea28db..4b7f45be 100644 --- a/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-ratelimit.md +++ b/spring-cloud-tencent-docs/src/main/doc/spring-cloud-tencent-polaris-ratelimit.md @@ -24,7 +24,7 @@ Default introduce spring-cloud-starter-tencent-polaris-ratelimit dependencies ca This chapter will explain how to use Polaris RateLimit in Spring Cloud project with the easiest way. Before starting MicroService, one needs to launch Polaris. Please refer to [Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started). -1. you can add ```spring-cloud-starter-tencent-polaris-ratelimit```‘s dependencies in your project to use the rate limit feature. For example, in Maven's project, add listed: +1. You can add ```spring-cloud-starter-tencent-polaris-ratelimit```‘s dependencies in your project to use the rate limit feature. For example, in Maven's project, add listed: ```XML diff --git a/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/conf/polaris.yml b/spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/polaris.yml similarity index 100% rename from spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/conf/polaris.yml rename to spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a/src/main/resources/polaris.yml diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml index e6074ce7..ea3cd0aa 100644 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml @@ -6,7 +6,7 @@ spring: name: DiscoveryCalleeService cloud: polaris: - address: grpc://127.0.0.1:8081 + address: grpc://127.0.0.1:8091 consul: port: 8500 host: 127.0.0.1 diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml new file mode 100644 index 00000000..c6a3d334 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/polaris.yml @@ -0,0 +1,6 @@ +global: + system: + discoverCluster: + sameAsBuiltin: true + healthCheckCluster: + sameAsBuiltin: true \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml index 6d569399..43930793 100644 --- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml @@ -6,7 +6,7 @@ spring: name: DiscoveryCallerService cloud: polaris: - address: grpc://127.0.0.1:8081 + address: grpc://127.0.0.1:8091 consul: port: 8500 host: 127.0.0.1 diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml new file mode 100644 index 00000000..c6a3d334 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/polaris.yml @@ -0,0 +1,6 @@ +global: + system: + discoverCluster: + sameAsBuiltin: true + healthCheckCluster: + sameAsBuiltin: true \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml index e93c697e..2ca31ba4 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service/src/main/resources/application.yml @@ -6,4 +6,4 @@ spring: name: GatewayCalleeService cloud: polaris: - address: grpc://127.0.0.1:8081 \ No newline at end of file + address: grpc://127.0.0.1:8091 \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml index 7809bb23..59f5467d 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: name: GatewayScgService cloud: polaris: - address: grpc://127.0.0.1:8081 + address: grpc://127.0.0.1:8091 tencent: metadata: content: diff --git a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml index bff70581..c191c5e4 100644 --- a/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml +++ b/spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service/src/main/resources/application.yml @@ -6,7 +6,7 @@ spring: name: GatewayZuulService cloud: polaris: - address: grpc://127.0.0.1:8081 + address: grpc://127.0.0.1:8091 tencent: metadata: content: diff --git a/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java b/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java index f7e22314..289dcaf1 100644 --- a/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java +++ b/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/PolarisContextProperties.java @@ -63,6 +63,7 @@ public class PolarisContextProperties { protected Configuration configuration() { ConfigurationImpl configuration = (ConfigurationImpl) ConfigAPIFactory .defaultConfig(ConfigProvider.DEFAULT_CONFIG); + configuration.setDefault(); String defaultHost = getHost(); configuration.getGlobal().getAPI().setBindIP(defaultHost); Collection modifiers = modifierList;