diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 000000000..44439fd8d
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,40 @@
+version: 2
+jobs:
+ build:
+ docker:
+ - image: springcloud/pipeline-base
+ user: appuser
+ environment:
+ _JAVA_OPTIONS: "-Xms1024m -Xmx2048m"
+ TERM: dumb
+ branches:
+ ignore:
+ - gh-pages # list of branches to ignore
+ resource_class: large
+ steps:
+ - checkout
+ - restore_cache:
+ key: sc-alibaba-{{ .Branch }}
+ - run:
+ name: "Download dependencies"
+ command: ./mvnw -Pspring -U --fail-never dependency:go-offline || true
+ - save_cache:
+ key: sc-alibaba-{{ .Branch }}
+ paths:
+ - ~/.m2
+ - run:
+ name: "Running build"
+ command: ./mvnw -Pspring clean install -U -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
+ - run:
+ name: "Aggregate test results"
+ when: always
+ command: |
+ mkdir -p ~/junit/
+ find . -type f -regex ".*/target/.*-reports/.*" -exec cp {} ~/junit/ \;
+ bash <(curl -s https://codecov.io/bash)
+ - store_artifacts:
+ path: ~/junit/
+ destination: artifacts
+ - store_test_results:
+ path: ~/junit/
+ destination: testartifacts
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index e4b662ae1..e02b722f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,4 +28,5 @@ hs_err_pid*
.project
.settings
target
+.DS_Store
diff --git a/README-zh.md b/README-zh.md
index 54a9cfa12..c6afae181 100644
--- a/README-zh.md
+++ b/README-zh.md
@@ -8,7 +8,7 @@ Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解
## 主要功能
* **服务限流降级**:默认支持为 HTTP 服务的提供限流保护,也支持添加注解实现方法的自定义限流降级,且支持动态修改限流降级规则。
-* **服务注册与发现**:适配 sprig cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。
+* **服务注册与发现**:适配 Spring Cloud 服务注册与发现标准,默认集成了 Ribbon 的支持。
* **分布式配置管理**:支持分布式系统中的外部化配置,配置更改时自动刷新。
* **阿里云对象存储**:阿里云提供的海量、安全、低成本、高可靠的云存储服务。支持在任何应用、任何时间、任何地点存储和访问任意类型的数据。
diff --git a/README.md b/README.md
index c0941db39..c69092a13 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# Spring Cloud Alibaba
+A project maintained by Alibaba.
+
See the [中文文档](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/README-zh.md) for Chinese readme.
Spring Cloud Alibaba provides a one-stop solution for distributed application development. It contains all the components required to develop distributed applications, making it easy for you to develop your applications using Spring Cloud.
diff --git a/pom.xml b/pom.xml
index 1353ad3e7..c10db5423 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,13 +8,13 @@
org.springframework.cloud
spring-cloud-build
- 2.0.0.RELEASE
+ 2.0.4.RELEASE
org.springframework.cloud
spring-cloud-alibaba
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
pom
Spring Cloud Alibaba
@@ -28,12 +28,12 @@
- https://github.com/spring-cloud-incubator/spring-cloud-alibabacloud
+ https://github.com/spring-cloud-incubator/spring-cloud-alibaba
- scm:git:git://github.com/spring-cloud-incubator/spring-cloud-alibabacloud.git
+ scm:git:git://github.com/spring-cloud-incubator/spring-cloud-alibaba.git
- scm:git:ssh://git@github.com/spring-cloud-incubator/spring-cloud-alibabacloud.git
+ scm:git:ssh://git@github.com/spring-cloud-incubator/spring-cloud-alibaba.git
HEAD
@@ -47,6 +47,10 @@
fangjian
fangjian0423@gmail.com
+
+ xiaolongzuo
+ 150349407@qq.com
+
hengyunabc
hengyunabc@gmail.com
@@ -55,9 +59,9 @@
- 2.0.0.RELEASE
- 2.0.0.RELEASE
- 2.0.0.RELEASE
+ 2.0.2.RELEASE
+ 2.0.2.RELEASE
+ 2.0.2.RELEASE
4.12
3.0
@@ -74,7 +78,7 @@
spring-cloud-alibaba-dependencies
spring-cloud-alibaba-sentinel
-
+ spring-cloud-alibaba-sentinel-datasource
spring-cloud-alibaba-nacos-config
spring-cloud-alibaba-nacos-discovery
spring-cloud-alibaba-examples
@@ -82,6 +86,9 @@
spring-cloud-starter-alibaba
spring-cloud-starter-alicloud
spring-cloud-alicloud-oss
+ spring-cloud-alicloud-context
+ spring-cloud-alicloud-acm
+ spring-cloud-alicloud-ans
@@ -154,4 +161,69 @@
+
+
+
+ spring
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/libs-snapshot-local
+
+ true
+
+
+ false
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/libs-milestone-local
+
+ false
+
+
+
+ spring-releases
+ Spring Releases
+ https://repo.spring.io/release
+
+ false
+
+
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/libs-snapshot-local
+
+ true
+
+
+ false
+
+
+
+ spring-milestones
+ Spring Milestones
+ https://repo.spring.io/libs-milestone-local
+
+ false
+
+
+
+ spring-releases
+ Spring Releases
+ https://repo.spring.io/libs-release-local
+
+ false
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml
index 167f71e9d..33b5ad6af 100644
--- a/spring-cloud-alibaba-dependencies/pom.xml
+++ b/spring-cloud-alibaba-dependencies/pom.xml
@@ -6,24 +6,60 @@
spring-cloud-dependencies-parent
org.springframework.cloud
- 2.0.0.RELEASE
+ 2.0.4.RELEASE
spring-cloud-alibaba-dependencies
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
pom
Spring Cloud Alibaba Dependencies
Spring Cloud Alibaba Dependencies
- 0.2.0
+ 1.3.0-GA
3.1.0
- 0.2.1
+ 0.3.0
+ 1.0.8
+ 0.1.1
+ 4.0.1
+ 1.0.0
+ 2.16.0
-
+
+
+ com.alibaba.cloud
+ alicloud-context
+ ${alicloud.context.version}
+
+
+ com.aliyun
+ aliyun-java-sdk-edas
+ ${aliyun.sdk.edas.version}
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+
+
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+ ${aliyun.sdk.version}
+
+
+ com.alibaba.ans
+ ans-sdk
+ ${ans.version}
+
+
+ com.alibaba.edas.acm
+ acm-sdk
+ ${acm.version}
+
com.alibaba.nacos
nacos-client
@@ -95,6 +131,11 @@
spring-cloud-alibaba-sentinel
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-alibaba-sentinel-datasource
+ ${project.version}
+
org.springframework.cloud
spring-cloud-alicloud-oss
@@ -110,6 +151,21 @@
spring-cloud-alibaba-nacos-config
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-alicloud-acm
+ ${project.version}
+
+
+ org.springframework.cloud
+ spring-cloud-alicloud-ans
+ ${project.version}
+
+
+ org.springframework.cloud
+ spring-cloud-alicloud-context
+ ${project.version}
+
@@ -135,9 +191,17 @@
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+ ${project.version}
+
-
-
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-acm
+ ${project.version}
+
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/pom.xml b/spring-cloud-alibaba-examples/acm-example/acm-local-example/pom.xml
new file mode 100644
index 000000000..35296f912
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.1.BUILD-SNAPSHOT
+
+ 4.0.0
+ acm-local-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-acm
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AcmApplication.java b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AcmApplication.java
new file mode 100644
index 000000000..5d48c381d
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AcmApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+public class AcmApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(AcmApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
new file mode 100644
index 000000000..b7c874610
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class EchoController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EchoController.class);
+
+ @Value("${user.id}")
+ private String userId;
+
+ @RequestMapping(value = "/")
+ public String echo() {
+ LOGGER.info("User id is " + userId);
+ return userId;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties
new file mode 100644
index 000000000..448a0c7dd
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties
@@ -0,0 +1,5 @@
+spring.application.group=com.alibaba.acm
+spring.application.name=acm-local
+server.port=18089
+spring.cloud.alicloud.acm.server-list=127.0.0.1
+spring.cloud.alicloud.acm.server-port=8080
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/pom.xml b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/pom.xml
new file mode 100644
index 000000000..21ea6aae7
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/pom.xml
@@ -0,0 +1,31 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.1.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-consumer-feign-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
new file mode 100644
index 000000000..e95b2e9cf
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableFeignClients(basePackages = {"org.springframework.cloud.alibaba.cloud.examples"})
+public class ConsumerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ConsumerApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java
new file mode 100644
index 000000000..78b3c486a
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author xiaolongzuo
+ */
+@FeignClient(value = "ans-provider")
+public interface EchoService {
+
+ @RequestMapping(path = "echo/{str}")
+ String echo(@RequestParam("str") String param);
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
new file mode 100644
index 000000000..8f2a3e8c2
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class HomeController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);
+
+ @Autowired
+ private EchoService echoService;
+
+ @RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
+ public String home() {
+ LOGGER.info("-----------------consumer调用开始-----------------");
+ String param = "Nice to meet you.";
+ LOGGER.info("消费者传递参数:" + param);
+ String result = echoService.echo(param);
+ LOGGER.info("收到提供者响应:" + result);
+ return param + "
" + result;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties
new file mode 100644
index 000000000..542653d94
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+server.port=18083
+# The following configuration can be omitted.
+spring.cloud.alicloud.ans.server.list=127.0.0.1
+spring.cloud.alicloud.ans.server.port=8080
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/pom.xml b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/pom.xml
new file mode 100644
index 000000000..775a2739e
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.1.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-consumer-ribbon-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
new file mode 100644
index 000000000..223a2d891
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+public class ConsumerApplication {
+
+ @Bean
+ @LoadBalanced
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(ConsumerApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
new file mode 100644
index 000000000..e3853fdd3
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class HomeController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
+ public String home() {
+ LOGGER.info("-----------------consumer调用开始-----------------");
+ String param = "Nice to meet you.";
+ LOGGER.info("消费者传递参数:" + param);
+ String result = restTemplate.getForObject("http://ans-provider/echo/" + param, String.class);
+ LOGGER.info("收到提供者响应:" + result);
+ return param + "
" + result;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties
new file mode 100644
index 000000000..315a90331
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+server.port=18082
+# The following configuration can be omitted.
+spring.cloud.alicloud.ans.server.list=127.0.0.1
+spring.cloud.alicloud.ans.server.port=8080
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/pom.xml b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/pom.xml
new file mode 100644
index 000000000..cbe5509ca
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.1.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-provider-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
new file mode 100644
index 000000000..a9c031ead
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class EchoController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EchoController.class);
+
+ @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET, produces = "application/json")
+ public String echo(@PathVariable String str) {
+ LOGGER.info("-----------收到消费者请求-----------");
+ LOGGER.info("收到消费者传递的参数:" + str);
+ String result = "Nice to meet you, too.";
+ LOGGER.info("提供者返回结果:" + result);
+ return result;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java
new file mode 100644
index 000000000..03436dcb4
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+public class ProviderApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ProviderApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties
new file mode 100644
index 000000000..2fb389e2e
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+spring.application.name=ans-provider
+server.port=18081
+spring.cloud.alicloud.ans.server.list=127.0.0.1
+spring.cloud.alicloud.ans.server.port=8080
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/pom.xml
index a011d829a..7ee827cb9 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/pom.xml
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme-zh.md b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme-zh.md
index bef4f89d1..e7339058c 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme-zh.md
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme-zh.md
@@ -19,9 +19,10 @@
spring-cloud-starter-alibaba-nacos-config
-2. 在应用的 /src/main/resources/bootstrap.properties 配置文件中配置 Nacos Config 地址
+2. 在应用的 /src/main/resources/bootstrap.properties 配置文件中配置 Nacos Config 元数据
- spring.cloud.nacos.config.server-addr=127.0.0.1:8848
+ spring.application.name=nacos-config-example
+ spring.cloud.nacos.config.server-addr=127.0.0.1:8848
3. 完成上述两步后,应用会从 Nacos Config 中获取相应的配置,并添加在 Spring Environment 的 PropertySources 中。这里我们使用 @Value 注解来将对应的配置注入到 SampleController 的 userName 和 age 字段,并添加 @RefreshScope 打开动态刷新功能
@@ -70,8 +71,8 @@
1. 增加配置,在应用的 /src/main/resources/application.properties 中添加基本配置信息
- spring.application.name=nacos-config-example
- server.port=18084
+ server.port=18084
+ management.endpoints.web.exposure.include=*
2. 启动应用,支持 IDE 直接启动和编译打包后启动。
@@ -118,9 +119,9 @@ Nacos Client 从 Nacos Server 端获取数据时,调用的是此接口 `Config
* `spring.active.profile` 即为当前环境对应的 profile,详情可以参考 [Spring Boot文档](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html#boot-features-profiles)
- **注意,当 activeprofile 为空时,对应的连接符 `-` 也将不存在,dataId 的拼接格式变成 `${prefix}`.`${context.type}`**
+ **注意,当 activeprofile 为空时,对应的连接符 `-` 也将不存在,dataId 的拼接格式变成 `${prefix}`.`${file-extension}`**
-* `file-extension` 为配置内容的数据格式,可以通过配置项 `spring.cloud.nacos.config.content-type`来配置。
+* `file-extension` 为配置内容的数据格式,可以通过配置项 `spring.cloud.nacos.config.file-extension`来配置。
目前只支持 `properties` 类型。
#### group
@@ -168,7 +169,7 @@ Spring Boot 2.x 可以通过访问 http://127.0.0.1:18084/actuator/nacos-config
服务端地址|spring.cloud.nacos.config.server-addr||
DataId前缀|spring.cloud.nacos.config.prefix||spring.application.name
Group|spring.cloud.nacos.config.group|DEFAULT_GROUP|
-dataID后缀及数据格式|spring.cloud.nacos.config.file-extension|properties|目前只支持 properties
+dataID后缀及内容文件格式|spring.cloud.nacos.config.file-extension|properties|dataId的后缀,同时也是配置内容的文件格式,目前只支持 properties
配置内容的编码方式|spring.cloud.nacos.config.encode|UTF-8|配置的编码
获取配置的超时时间|spring.cloud.nacos.config.timeout|3000|单位为 ms
配置的命名空间|spring.cloud.nacos.config.namespace||常用场景之一是不同环境的配置的区分隔离,例如开发测试环境和生产环境的资源隔离等。
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme.md b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme.md
index 05bda7fc7..58b499aef 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme.md
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme.md
@@ -19,9 +19,10 @@ Before we start the demo, let's learn how to connect Nacos Config to a Spring Cl
spring-cloud-starter-alibaba-nacos-config
-2. Add Nacos server address configurations to file /src/main/resources/bootstrap.properties
+2. Add Nacos config metadata configurations to file /src/main/resources/bootstrap.properties
- spring.cloud.nacos.config.server-addr=127.0.0.1:8848
+ spring.application.name=nacos-config-example
+ spring.cloud.nacos.config.server-addr=127.0.0.1:8848
3. After completing the above two steps, the application will get the externalized configuration from Nacos Server and put it in the Spring Environment's PropertySources.We use the @Value annotation to inject the corresponding configuration into the userName and age fields of the SampleController, and add @RefreshScope to turn on dynamic refresh .
@RefreshScope
@@ -70,8 +71,8 @@ Before we start the demo, let's learn how to connect Nacos Config to a Spring Cl
1. Add necessary configurations to file /src/main/resources/application.properties
- spring.application.name=nacos-config-example
- server.port=18084
+ server.port=18084
+ management.endpoints.web.exposure.include=*
2. Start the application in IDE or by building a fatjar.
@@ -119,9 +120,9 @@ In Nacos Config Starter, the splicing format of dataId is as follows
* `spring.active.profile` is the profile corresponding to the current environment. For details, please refer to [Spring Boot Doc](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html#boot-features-profiles)
- **Note: when the activeprofile is empty, the corresponding connector `-` will also not exist, and the splicing format of the dataId becomes `${prefix}`.`${context.type}`**
+ **Note: when the activeprofile is empty, the corresponding connector `-` will also not exist, and the splicing format of the dataId becomes `${prefix}`.`${file-extension}`**
-* `file-extension` is the data format of the configuration content, which can be configured by the configuration item `spring.cloud.nacos.config.content-type`.
+* `file-extension` is the data format of the configuration content, which can be configured by the configuration item `spring.cloud.nacos.config.file-extension`.
Currently only the `properties` type is supported.
#### group
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties
index a0e934e2a..c6e216ad7 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/application.properties
@@ -1,3 +1,2 @@
-spring.application.name=nacos-config-example
server.port=18084
management.endpoints.web.exposure.include=*
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties
index 8d94d562d..6adb653ca 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/resources/bootstrap.properties
@@ -1 +1,2 @@
+spring.application.name=nacos-config-example
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml
index 65fbbfb0d..2699f7c35 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
nacos-discovery-example
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
4.0.0
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/pom.xml
index c2e5952aa..1266769bf 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/pom.xml
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
nacos-discovery-example
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
4.0.0
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml
index d4041f669..5ad506a9e 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md
index a04451d36..47b431792 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md
@@ -197,7 +197,7 @@ AccessKey|spring.cloud.nacos.discovery.access-key||
SecretKey|spring.cloud.nacos.discovery.secret-key||
Metadata|spring.cloud.nacos.discovery.metadata||使用Map格式配置
日志文件名|spring.cloud.nacos.discovery.log-name||
-接入点|spring.cloud.nacos.discovery.enpoint|UTF-8|地域的某个服务的入口域名,通过此域名可以动态地拿到服务端地址
+接入点|spring.cloud.nacos.discovery.endpoint|UTF-8|地域的某个服务的入口域名,通过此域名可以动态地拿到服务端地址
是否集成Ribbon|ribbon.nacos.enabled|true|
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md
index cd26ef587..da81f49b7 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md
@@ -205,7 +205,7 @@ AccessKey|spring.cloud.nacos.discovery.access-key||
SecretKey|spring.cloud.nacos.discovery.secret-key||
Metadata|spring.cloud.nacos.discovery.metadata||Extended data, Configure using Map format
log name|spring.cloud.nacos.discovery.log-name||
-endpoint|spring.cloud.nacos.discovery.enpoint||The domain name of a service, through which the server address can be dynamically obtained.
+endpoint|spring.cloud.nacos.discovery.endpoint||The domain name of a service, through which the server address can be dynamically obtained.
Integration Ribbon|ribbon.nacos.enabled|true|
diff --git a/spring-cloud-alibaba-examples/oss-example/pom.xml b/spring-cloud-alibaba-examples/oss-example/pom.xml
index 33442b3ad..16e7b8974 100644
--- a/spring-cloud-alibaba-examples/oss-example/pom.xml
+++ b/spring-cloud-alibaba-examples/oss-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
4.0.0
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java
deleted file mode 100644
index 0e4546fac..000000000
--- a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.springframework.cloud.alibaba.cloud.examples;
-
-import java.net.URISyntaxException;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Bean;
-
-import com.aliyun.oss.OSS;
-
-/**
- * OSS Application
- *
- * @author Jim
- */
-@SpringBootApplication
-public class OSSApplication {
-
- public static final String BUCKET_NAME = "spring-cloud-alibaba";
-
- public static void main(String[] args) throws URISyntaxException {
- SpringApplication.run(OSSApplication.class, args);
- }
-
- @Bean
- public AppRunner appRunner() {
- return new AppRunner();
- }
-
- class AppRunner implements ApplicationRunner {
- @Autowired
- private OSS ossClient;
-
- @Override
- public void run(ApplicationArguments args) throws Exception {
- try {
- if (!ossClient.doesBucketExist(BUCKET_NAME)) {
- ossClient.createBucket(BUCKET_NAME);
- }
- }
- catch (Exception e) {
- System.err.println("oss handle bucket error: " + e.getMessage());
- System.exit(-1);
- }
- }
- }
-
-}
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java
deleted file mode 100644
index 1f3aac896..000000000
--- a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.springframework.cloud.alibaba.cloud.examples;
-
-import java.nio.charset.Charset;
-
-import org.apache.commons.codec.CharEncoding;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.io.Resource;
-import org.springframework.util.StreamUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.common.utils.IOUtils;
-import com.aliyun.oss.model.OSSObject;
-
-/**
- * OSS Controller
- *
- * @author Jim
- */
-@RestController
-public class OSSController {
-
- @Autowired
- private OSS ossClient;
-
- @Value("oss://" + OSSApplication.BUCKET_NAME + "/oss-test")
- private Resource file;
-
- private String dir = "custom-dir/";
-
- @GetMapping("/upload")
- public String upload() {
- try {
- ossClient.putObject(OSSApplication.BUCKET_NAME, dir + "oss-test", this
- .getClass().getClassLoader().getResourceAsStream("oss-test.json"));
- }
- catch (Exception e) {
- e.printStackTrace();
- return "upload fail: " + e.getMessage();
- }
- return "upload success";
- }
-
- @GetMapping("/file-resource")
- public String fileResource() {
- try {
- return "get file resource success. content: " + StreamUtils.copyToString(
- file.getInputStream(), Charset.forName(CharEncoding.UTF_8));
- }
- catch (Exception e) {
- e.printStackTrace();
- return "get resource fail: " + e.getMessage();
- }
- }
-
- @GetMapping("/download")
- public String download() {
- try {
- OSSObject ossObject = ossClient.getObject(OSSApplication.BUCKET_NAME,
- dir + "oss-test");
- return "download success, content: " + IOUtils
- .readStreamAsString(ossObject.getObjectContent(), CharEncoding.UTF_8);
- }
- catch (Exception e) {
- e.printStackTrace();
- return "download fail: " + e.getMessage();
- }
- }
-
-}
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssApplication.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssApplication.java
new file mode 100644
index 000000000..f9265800d
--- /dev/null
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssApplication.java
@@ -0,0 +1,49 @@
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import com.aliyun.oss.OSS;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+
+import java.net.URISyntaxException;
+
+/**
+ * OSS Application
+ *
+ * @author Jim
+ */
+@SpringBootApplication
+public class OssApplication {
+
+ public static final String BUCKET_NAME = "spring-cloud-alibaba-test";
+
+ public static void main(String[] args) throws URISyntaxException {
+ SpringApplication.run(OssApplication.class, args);
+ }
+
+ @Bean
+ public AppRunner appRunner() {
+ return new AppRunner();
+ }
+
+ class AppRunner implements ApplicationRunner {
+ @Autowired
+ private OSS ossClient;
+
+ @Override
+ public void run(ApplicationArguments args) throws Exception {
+ try {
+ if (!ossClient.doesBucketExist(BUCKET_NAME)) {
+ ossClient.createBucket(BUCKET_NAME);
+ }
+ } catch (Exception e) {
+ System.err.println("oss handle bucket error: " + e.getMessage());
+ System.exit(-1);
+ }
+ }
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssController.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssController.java
new file mode 100644
index 000000000..7c6e427a9
--- /dev/null
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssController.java
@@ -0,0 +1,65 @@
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.common.utils.IOUtils;
+import com.aliyun.oss.model.OSSObject;
+import org.apache.commons.codec.CharEncoding;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.Resource;
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.nio.charset.Charset;
+
+/**
+ * OSS Controller
+ *
+ * @author Jim
+ */
+@RestController
+public class OssController {
+
+ @Autowired
+ private OSS ossClient;
+
+ @Value("oss://" + OssApplication.BUCKET_NAME + "/oss-test.json")
+ private Resource file;
+
+ @GetMapping("/upload")
+ public String upload() {
+ try {
+ ossClient.putObject(OssApplication.BUCKET_NAME, "oss-test.json", this
+ .getClass().getClassLoader().getResourceAsStream("oss-test.json"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "upload fail: " + e.getMessage();
+ }
+ return "upload success";
+ }
+
+ @GetMapping("/file-resource")
+ public String fileResource() {
+ try {
+ return "get file resource success. content: " + StreamUtils.copyToString(
+ file.getInputStream(), Charset.forName(CharEncoding.UTF_8));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "get resource fail: " + e.getMessage();
+ }
+ }
+
+ @GetMapping("/download")
+ public String download() {
+ try {
+ OSSObject ossObject = ossClient.getObject(OssApplication.BUCKET_NAME, "oss-test.json");
+ return "download success, content: " + IOUtils
+ .readStreamAsString(ossObject.getObjectContent(), CharEncoding.UTF_8);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "download fail: " + e.getMessage();
+ }
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties
index 4b269483e..59c650d3d 100644
--- a/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties
@@ -1,8 +1,6 @@
spring.application.name=oss-example
server.port=18084
-
-spring.cloud.alibaba.oss.accessKeyId=[your-ak]
-spring.cloud.alibaba.oss.secretAccessKey=[your-sk]
-spring.cloud.alibaba.oss.region=[your-region]
-
-management.endpoints.web.exposure.include=*
\ No newline at end of file
+spring.cloud.alicloud.access-key=AK
+spring.cloud.alicloud.secret-key=SK
+spring.cloud.alicloud.oss.endpoint=***.aliyuncs.com
+management.endpoints.web.exposure.include=*
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json b/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json
index eb0fe5f89..f1683e94f 100644
--- a/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json
@@ -1,6 +1,3 @@
{
- "name": "spring-cloud-alibaba",
- "github": "https://github.com/spring-cloud-incubator/spring-cloud-alibaba",
- "authors": ["Jim", "flystar32"],
- "emails": ["fangjian0423@gmail.com", "flystar32@163.com"]
+ "name": "chenzhu-test"
}
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/pom.xml b/spring-cloud-alibaba-examples/pom.xml
index f02eadbb3..acdcb6049 100644
--- a/spring-cloud-alibaba-examples/pom.xml
+++ b/spring-cloud-alibaba-examples/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
4.0.0
@@ -23,6 +23,10 @@
nacos-example/nacos-discovery-example
nacos-example/nacos-config-example
oss-example
+ ans-example/ans-consumer-feign-example
+ ans-example/ans-consumer-ribbon-example
+ ans-example/ans-provider-example
+ acm-example/acm-local-example
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml
index 314ee8f82..91ae63304 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md
index 4c0b2aeba..c07c20e37 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md
@@ -222,7 +222,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置
`spring.cloud.sentinel.datasource.converter`代表 `Converter` 在 Spring 容器里的 name。如果没找到,会抛出异常。
-type目前支持file, nacos, zk, apollo。
+type目前支持file, nacos, zk, apollo。其中nacos,zk,apollo的使用需要加上对应的依赖`sentinel-datasource-nacos`, `sentinel-datasource-zookeeper`, `sentinel-datasource-apollo`
### 自定义DataSource
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md
index a51ed38ad..dcdd77fc3 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md
@@ -193,7 +193,8 @@ spring.cloud.sentinel.datasource.recommendRefreshMs means the recommendRefreshMs
spring.cloud.sentinel.datasource.converter means the name of spring bean that type is Converter. If the bean is not exists, will throw exception.
-Now datasource type support 4 categories: file, nacos, zk, apollo.
+Now datasource type support 4 categories: file, nacos, zk, apollo. If you want to using nacos, zk or apollo, you should add `sentinel-datasource-nacos`, `sentinel-datasource-zookeeper` or `sentinel-datasource-apollo` dependency.
+
### User-defined DataSource
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml
index 6c989f5da..898734b09 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
../../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml
index ba88981a0..d69b92ba3 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
../../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml
index c59f4ba61..2c48b6b71 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba-examples
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
../../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-nacos-config/pom.xml b/spring-cloud-alibaba-nacos-config/pom.xml
index 6bbc12173..59663771c 100644
--- a/spring-cloud-alibaba-nacos-config/pom.xml
+++ b/spring-cloud-alibaba-nacos-config/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
4.0.0
diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java
index f08969121..5dbdb50af 100644
--- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java
+++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfiguration.java
@@ -16,8 +16,6 @@
package org.springframework.cloud.alibaba.nacos;
-import com.alibaba.nacos.api.config.ConfigService;
-
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.refresh.NacosContextRefresher;
@@ -43,14 +41,6 @@ public class NacosConfigAutoConfiguration implements ApplicationContextAware {
@Autowired
private NacosRefreshProperties nacosRefreshProperties;
- @Autowired
- private ConfigService configService;
-
- @Bean
- public NacosConfigProperties nacosConfigProperties() {
- return new NacosConfigProperties();
- }
-
@Bean
public NacosPropertySourceRepository nacosPropertySourceRepository() {
return new NacosPropertySourceRepository(applicationContext);
@@ -69,10 +59,10 @@ public class NacosConfigAutoConfiguration implements ApplicationContextAware {
@Bean
public NacosContextRefresher nacosContextRefresher(ContextRefresher contextRefresher,
NacosRefreshHistory refreshHistory,
- NacosPropertySourceRepository propertySourceRepository,
- ConfigService configService) {
+ NacosPropertySourceRepository propertySourceRepository) {
return new NacosContextRefresher(contextRefresher, nacosConfigProperties,
- nacosRefreshProperties, refreshHistory, propertySourceRepository,configService);
+ nacosRefreshProperties, refreshHistory, propertySourceRepository,
+ nacosConfigProperties.configServiceInstance());
}
@Override
diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java
index d5e3bd3b8..e643d35a8 100644
--- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java
+++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfiguration.java
@@ -16,6 +16,7 @@
package org.springframework.cloud.alibaba.nacos;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -32,6 +33,7 @@ public class NacosConfigBootstrapConfiguration {
}
@Bean
+ @ConditionalOnMissingBean
public NacosConfigProperties nacosConfigProperties() {
return new NacosConfigProperties();
}
diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java
index 446483d69..e279d9cbe 100644
--- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java
+++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/NacosConfigProperties.java
@@ -16,9 +16,30 @@
package org.springframework.cloud.alibaba.nacos;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Properties;
+
+import javax.annotation.PostConstruct;
+
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.config.ConfigService;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
-import org.springframework.util.StringUtils;
+
+import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
+import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
+import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
+import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
+import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
+import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
+import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
+import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
/**
* nacos properties
@@ -29,6 +50,9 @@ import org.springframework.util.StringUtils;
@ConfigurationProperties("spring.cloud.nacos.config")
public class NacosConfigProperties {
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(NacosConfigProperties.class);
+
/**
* nacos config server address
*/
@@ -89,6 +113,21 @@ public class NacosConfigProperties {
*/
private String clusterName;
+ @Value("${spring.application.name}")
+ private String name;
+
+ private String[] activeProfiles;
+
+ private ConfigService configService;
+
+ @Autowired
+ private Environment environment;
+
+ @PostConstruct
+ public void init() {
+ this.activeProfiles = environment.getActiveProfiles();
+ }
+
// todo sts support
public String getServerAddr() {
@@ -187,6 +226,14 @@ public class NacosConfigProperties {
this.clusterName = clusterName;
}
+ public String getName() {
+ return name;
+ }
+
+ public String[] getActiveProfiles() {
+ return activeProfiles;
+ }
+
@Override
public String toString() {
return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\''
@@ -195,46 +242,32 @@ public class NacosConfigProperties {
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
- + '\'' + ", clusterName='" + clusterName + '\'' + '}';
+ + '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
+ + ", activeProfiles=" + Arrays.toString(activeProfiles) + '}';
}
- public void overrideFromEnv(Environment env) {
+ public ConfigService configServiceInstance() {
- if (StringUtils.isEmpty(this.getServerAddr())) {
- this.setServerAddr(
- env.resolvePlaceholders("${spring.cloud.nacos.config.server-addr:}"));
- }
- if (StringUtils.isEmpty(this.getEncode())) {
- this.setEncode(
- env.resolvePlaceholders("${spring.cloud.nacos.config.encode:}"));
- }
- if (StringUtils.isEmpty(this.getNamespace())) {
- this.setNamespace(
- env.resolvePlaceholders("${spring.cloud.nacos.config.namespace:}"));
+ if (null != configService) {
+ return configService;
}
- if (StringUtils.isEmpty(this.getAccessKey())) {
- this.setAccessKey(
- env.resolvePlaceholders("${spring.cloud.nacos.config.access-key:}"));
- }
- if (StringUtils.isEmpty(this.getSecretKey())) {
- this.setSecretKey(
- env.resolvePlaceholders("${spring.cloud.nacos.config.secret-key:}"));
- }
- if (StringUtils.isEmpty(this.getContextPath())) {
- this.setContextPath(env
- .resolvePlaceholders("${spring.cloud.nacos.config.context-path:}"));
- }
- if (StringUtils.isEmpty(this.getClusterName())) {
- this.setClusterName(env
- .resolvePlaceholders("${spring.cloud.nacos.config.cluster-name:}"));
- }
- if (StringUtils.isEmpty(this.getEndpoint())) {
- this.setEndpoint(
- env.resolvePlaceholders("${spring.cloud.nacos.config.endpoint:}"));
+
+ Properties properties = new Properties();
+ properties.put(SERVER_ADDR, Objects.toString(this.serverAddr, ""));
+ properties.put(ENCODE, Objects.toString(this.encode, ""));
+ properties.put(NAMESPACE, Objects.toString(this.namespace, ""));
+ properties.put(ACCESS_KEY, Objects.toString(this.accessKey, ""));
+ properties.put(SECRET_KEY, Objects.toString(this.secretKey, ""));
+ properties.put(CONTEXT_PATH, Objects.toString(this.contextPath, ""));
+ properties.put(CLUSTER_NAME, Objects.toString(this.clusterName, ""));
+ properties.put(ENDPOINT, Objects.toString(this.endpoint, ""));
+ try {
+ configService = NacosFactory.createConfigService(properties);
+ return configService;
}
- if (StringUtils.isEmpty(this.getPrefix())) {
- this.setPrefix(
- env.resolvePlaceholders("${spring.cloud.nacos.config.prefix:}"));
+ catch (Exception e) {
+ LOGGER.error("create config service error!properties={},e=,", this, e);
+ return null;
}
}
}
diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceBuilder.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceBuilder.java
index 4e5d63b67..16bf97d09 100644
--- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceBuilder.java
+++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceBuilder.java
@@ -83,7 +83,6 @@ public class NacosPropertySourceBuilder {
String data = null;
try {
data = configService.getConfig(dataId, group, timeout);
- // todo add content type yaml support
if (!StringUtils.isEmpty(data)) {
logger.info(String.format("Loading nacos data, dataId: '%s', group: '%s'",
dataId, group));
@@ -95,7 +94,7 @@ public class NacosPropertySourceBuilder {
return properties;
}
else if (fileExtension.equalsIgnoreCase("yaml")
- || fileExtension.equalsIgnoreCase("yml")) {
+ || fileExtension.equalsIgnoreCase("yml")) {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
return yamlFactory.getObject();
diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceLocator.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceLocator.java
index f507f1522..304fc5672 100644
--- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceLocator.java
+++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/client/NacosPropertySourceLocator.java
@@ -16,12 +16,9 @@
package org.springframework.cloud.alibaba.nacos.client;
-import java.util.Properties;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.annotation.Order;
@@ -30,11 +27,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.util.StringUtils;
-import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
-import com.alibaba.nacos.api.exception.NacosException;
-
-import static com.alibaba.nacos.api.PropertyKeyConst.*;
/**
* @author xiaojing
@@ -48,47 +41,15 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
private static final String SEP1 = "-";
private static final String DOT = ".";
- @Autowired
- private ConfigurableListableBeanFactory beanFactory;
-
@Autowired
private NacosConfigProperties nacosConfigProperties;
- private ConfigService configService;
-
private NacosPropertySourceBuilder nacosPropertySourceBuilder;
- private Properties getPropertiesFromEnv(Environment env) {
-
- nacosConfigProperties.overrideFromEnv(env);
-
- Properties properties = new Properties();
- properties.put(SERVER_ADDR, nacosConfigProperties.getServerAddr());
- properties.put(ENCODE, nacosConfigProperties.getEncode());
- properties.put(NAMESPACE, nacosConfigProperties.getNamespace());
- properties.put(ACCESS_KEY, nacosConfigProperties.getAccessKey());
- properties.put(SECRET_KEY, nacosConfigProperties.getSecretKey());
- properties.put(CONTEXT_PATH, nacosConfigProperties.getContextPath());
- properties.put(CLUSTER_NAME, nacosConfigProperties.getClusterName());
- properties.put(ENDPOINT, nacosConfigProperties.getEndpoint());
- return properties;
- }
-
@Override
public PropertySource> locate(Environment env) {
- Properties properties = getPropertiesFromEnv(env);
-
- try {
- configService = NacosFactory.createConfigService(properties);
- }
- catch (NacosException e) {
- logger.error("create config service error, nacosConfigProperties:{}, ",
- properties, e);
- return null;
- }
-
- beanFactory.registerSingleton("configService", configService);
+ ConfigService configService = nacosConfigProperties.configServiceInstance();
if (null == configService) {
logger.warn(
@@ -99,13 +60,12 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
nacosPropertySourceBuilder = new NacosPropertySourceBuilder(configService,
timeout);
- String applicationName = env.getProperty("spring.application.name");
- logger.info("Initialize spring.application.name '" + applicationName + "'.");
+ String name = nacosConfigProperties.getName();
String nacosGroup = nacosConfigProperties.getGroup();
String dataIdPrefix = nacosConfigProperties.getPrefix();
if (StringUtils.isEmpty(dataIdPrefix)) {
- dataIdPrefix = applicationName;
+ dataIdPrefix = name;
}
String fileExtension = nacosConfigProperties.getFileExtension();
@@ -113,23 +73,21 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
CompositePropertySource composite = new CompositePropertySource(
NACOS_PROPERTY_SOURCE_NAME);
- loadApplicationConfiguration(composite, env, nacosGroup, dataIdPrefix,
- fileExtension);
+ loadApplicationConfiguration(composite, nacosGroup, dataIdPrefix, fileExtension);
return composite;
}
private void loadApplicationConfiguration(
- CompositePropertySource compositePropertySource, Environment environment,
- String nacosGroup, String dataIdPrefix, String fileExtension) {
+ CompositePropertySource compositePropertySource, String nacosGroup,
+ String dataIdPrefix, String fileExtension) {
loadNacosDataIfPresent(compositePropertySource,
dataIdPrefix + DOT + fileExtension, nacosGroup, fileExtension);
- for (String profile : environment.getActiveProfiles()) {
+ for (String profile : nacosConfigProperties.getActiveProfiles()) {
String dataId = dataIdPrefix + SEP1 + profile + DOT + fileExtension;
loadNacosDataIfPresent(compositePropertySource, dataId, nacosGroup,
fileExtension);
}
- // todo multi profile active order and priority
}
private void loadNacosDataIfPresent(final CompositePropertySource composite,
diff --git a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java
index d6d8464bb..c0d92632f 100644
--- a/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java
+++ b/spring-cloud-alibaba-nacos-config/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosConfigEndpointAutoConfiguration.java
@@ -16,8 +16,6 @@
package org.springframework.cloud.alibaba.nacos.endpoint;
-import com.alibaba.nacos.api.config.ConfigService;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -46,15 +44,6 @@ public class NacosConfigEndpointAutoConfiguration {
@Autowired
private NacosPropertySourceRepository nacosPropertySourceRepository;
- @Autowired
- private ConfigService configService;
-
- @Bean
- @ConditionalOnBean
- public NacosConfigProperties nacosConfigProperties() {
- return new NacosConfigProperties();
- }
-
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@Bean
@@ -67,6 +56,7 @@ public class NacosConfigEndpointAutoConfiguration {
public NacosConfigHealthIndicator nacosConfigHealthIndicator(
NacosPropertySourceRepository nacosPropertySourceRepository) {
return new NacosConfigHealthIndicator(nacosConfigProperties,
- nacosPropertySourceRepository, configService);
+ nacosPropertySourceRepository,
+ nacosConfigProperties.configServiceInstance());
}
}
diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfigurationTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfigurationTests.java
index 389e4fd20..66126759f 100644
--- a/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfigurationTests.java
+++ b/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigAutoConfigurationTests.java
@@ -39,66 +39,59 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class NacosConfigAutoConfigurationTests {
- private ConfigurableApplicationContext context;
-
- @Before
- public void setUp() throws Exception {
- this.context = new SpringApplicationBuilder(
- NacosConfigBootstrapConfiguration.class,
- NacosConfigAutoConfiguration.class,
- TestConfiguration.class)
- .web(WebApplicationType.NONE).run(
- "--spring.cloud.config.enabled=true",
- "--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
- "--spring.cloud.nacos.config.prefix=myapp");
- }
-
- @After
- public void tearDown() throws Exception {
- if (this.context != null) {
- this.context.close();
- }
- }
-
- @Test
- public void testNacosConfigProperties() {
-
- NacosPropertySourceLocator nacosPropertySourceLocator = this.context.getBean(NacosPropertySourceLocator.class);
- Environment environment = this.context.getEnvironment();
- try{
- nacosPropertySourceLocator.locate(environment);
- }catch (Exception e){
-
- }
-
- NacosConfigProperties nacosConfigProperties = this.context.getBean(NacosConfigProperties.class);
- assertThat(nacosConfigProperties.getFileExtension()).isEqualTo("properties");
- assertThat(nacosConfigProperties.getPrefix()).isEqualTo("myapp");
-
- }
-
-
- @Test
- public void testNacosRefreshProperties() {
-
- NacosRefreshProperties nacosRefreshProperties = this.context.getBean(NacosRefreshProperties.class);
- assertThat(nacosRefreshProperties.isEnabled()).isEqualTo(true);
-
- }
-
- @Configuration
- @AutoConfigureBefore(NacosConfigAutoConfiguration.class)
- static class TestConfiguration{
-
-
- @Autowired
- ConfigurableApplicationContext context;
-
- @Bean
- ContextRefresher contextRefresher(){
- return new ContextRefresher(context, new RefreshScope());
- }
-
- }
+ private ConfigurableApplicationContext context;
+
+ @Before
+ public void setUp() throws Exception {
+ this.context = new SpringApplicationBuilder(
+ NacosConfigBootstrapConfiguration.class,
+ NacosConfigAutoConfiguration.class, TestConfiguration.class)
+ .web(WebApplicationType.NONE)
+ .run("--spring.application.name=myapp",
+ "--spring.cloud.config.enabled=true",
+ "--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
+ "--spring.cloud.nacos.config.prefix=test");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (this.context != null) {
+ this.context.close();
+ }
+ }
+
+ @Test
+ public void testNacosConfigProperties() {
+
+ NacosConfigProperties nacosConfigProperties = this.context.getParent()
+ .getBean(NacosConfigProperties.class);
+ assertThat(nacosConfigProperties.getFileExtension()).isEqualTo("properties");
+ assertThat(nacosConfigProperties.getPrefix()).isEqualTo("test");
+ assertThat(nacosConfigProperties.getName()).isEqualTo("myapp");
+
+ }
+
+ @Test
+ public void testNacosRefreshProperties() {
+
+ NacosRefreshProperties nacosRefreshProperties = this.context
+ .getBean(NacosRefreshProperties.class);
+ assertThat(nacosRefreshProperties.isEnabled()).isEqualTo(true);
+
+ }
+
+ @Configuration
+ @AutoConfigureBefore(NacosConfigAutoConfiguration.class)
+ static class TestConfiguration {
+
+ @Autowired
+ ConfigurableApplicationContext context;
+
+ @Bean
+ ContextRefresher contextRefresher() {
+ return new ContextRefresher(context, new RefreshScope());
+ }
+
+ }
}
diff --git a/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfigurationTests.java b/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfigurationTests.java
index ae43f03f7..73cc98803 100644
--- a/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfigurationTests.java
+++ b/spring-cloud-alibaba-nacos-config/src/test/java/org/springframework/cloud/alibaba/nacos/NacosConfigBootstrapConfigurationTests.java
@@ -43,9 +43,10 @@ public class NacosConfigBootstrapConfigurationTests {
public void setUp() throws Exception {
this.context = new SpringApplicationBuilder(
NacosConfigBootstrapConfiguration.class).web(WebApplicationType.NONE).run(
+ "--spring.application.name=myapp",
"--spring.cloud.config.enabled=true",
"--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
- "--spring.cloud.nacos.config.prefix=myapp");
+ "--spring.cloud.nacos.config.prefix=test");
}
@After
@@ -68,15 +69,14 @@ public class NacosConfigBootstrapConfigurationTests {
}
- Field configServiceField = ReflectionUtils
- .findField(NacosPropertySourceLocator.class, "configService");
- configServiceField.setAccessible(true);
+ Field nacosConfigPropertiesField = ReflectionUtils
+ .findField(NacosPropertySourceLocator.class, "nacosConfigProperties");
+ nacosConfigPropertiesField.setAccessible(true);
- ConfigService configService = (ConfigService) ReflectionUtils
- .getField(configServiceField, locator);
+ NacosConfigProperties configService = (NacosConfigProperties) ReflectionUtils
+ .getField(nacosConfigPropertiesField, locator);
assertThat(configService).isNotNull();
}
-
}
diff --git a/spring-cloud-alibaba-nacos-discovery/pom.xml b/spring-cloud-alibaba-nacos-discovery/pom.xml
index e0aaa47d1..740c23982 100644
--- a/spring-cloud-alibaba-nacos-discovery/pom.xml
+++ b/spring-cloud-alibaba-nacos-discovery/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloud
spring-cloud-alibaba
- 0.2.0
+ 0.2.1.BUILD-SNAPSHOT
4.0.0
diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryClient.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryClient.java
index 59ea1ec73..1d22cd67d 100644
--- a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryClient.java
+++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryClient.java
@@ -19,15 +19,11 @@ package org.springframework.cloud.alibaba.nacos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
-import org.springframework.core.env.Environment;
import java.util.*;
-import javax.annotation.PostConstruct;
-
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
@@ -44,17 +40,6 @@ public class NacosDiscoveryClient implements DiscoveryClient {
@Autowired
private NacosDiscoveryProperties discoveryProperties;
- @Autowired
- private Environment environment;
-
- private NamingService namingService;
-
- @PostConstruct
- public void init() {
- discoveryProperties.overrideFromEnv(environment);
- namingService = discoveryProperties.getNamingService();
- }
-
@Override
public String description() {
return DESCRIPTION;
@@ -63,7 +48,8 @@ public class NacosDiscoveryClient implements DiscoveryClient {
@Override
public List getInstances(String serviceId) {
try {
- List instances = namingService.getAllInstances(serviceId);
+ List instances = discoveryProperties.namingServiceInstance()
+ .getAllInstances(serviceId);
return hostToServiceInstanceList(instances, serviceId);
}
catch (Exception e) {
@@ -103,8 +89,8 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public List getServices() {
try {
- ListView services = namingService.getServicesOfServer(1,
- Integer.MAX_VALUE);
+ ListView services = discoveryProperties.namingServiceInstance()
+ .getServicesOfServer(1, Integer.MAX_VALUE);
return services.getData();
}
catch (Exception e) {
@@ -114,6 +100,6 @@ public class NacosDiscoveryClient implements DiscoveryClient {
}
public NamingService getNamingService() {
- return namingService;
+ return discoveryProperties.namingServiceInstance();
}
}
diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryProperties.java
index aa9271a8d..fdb0d0e93 100644
--- a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryProperties.java
+++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryProperties.java
@@ -142,6 +142,11 @@ public class NacosDiscoveryProperties {
@Autowired
private InetUtils inetUtils;
+ @Autowired
+ private Environment environment;
+
+ private NamingService namingService;
+
@PostConstruct
public void init() throws SocketException {
@@ -180,6 +185,8 @@ public class NacosDiscoveryProperties {
}
}
+
+ this.overrideFromEnv(environment);
}
public String getEndpoint() {
@@ -350,7 +357,12 @@ public class NacosDiscoveryProperties {
}
}
- public NamingService getNamingService() {
+ public NamingService namingServiceInstance() {
+
+ if (null != namingService) {
+ return namingService;
+ }
+
Properties properties = new Properties();
properties.put(SERVER_ADDR, serverAddr);
properties.put(NAMESPACE, namespace);
@@ -360,7 +372,8 @@ public class NacosDiscoveryProperties {
properties.put(SECRET_KEY, secretKey);
properties.put(CLUSTER_NAME, clusterName);
try {
- return NacosFactory.createNamingService(properties);
+ namingService = NacosFactory.createNamingService(properties);
+ return namingService;
}
catch (Exception e) {
LOGGER.error("create naming service error!properties={},e=,", this, e);
diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosDiscoveryEndpoint.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosDiscoveryEndpoint.java
index db384df5e..1cbcfb87d 100644
--- a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosDiscoveryEndpoint.java
+++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/endpoint/NacosDiscoveryEndpoint.java
@@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
-import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
/**
@@ -45,9 +44,6 @@ public class NacosDiscoveryEndpoint {
@Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties;
- @Autowired
- private NacosDiscoveryClient discoveryClient;
-
/**
* @return nacos discovery endpoint
*/
@@ -56,7 +52,7 @@ public class NacosDiscoveryEndpoint {
Map result = new HashMap<>();
result.put("NacosDiscoveryProperties", nacosDiscoveryProperties);
- NamingService namingService = discoveryClient.getNamingService();
+ NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
List subscribe = Collections.emptyList();
try {
diff --git a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/registry/NacosRegistration.java b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/registry/NacosRegistration.java
index 639dad981..865358178 100644
--- a/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/registry/NacosRegistration.java
+++ b/spring-cloud-alibaba-nacos-discovery/src/main/java/org/springframework/cloud/alibaba/nacos/registry/NacosRegistration.java
@@ -48,15 +48,10 @@ public class NacosRegistration implements Registration, ServiceInstance {
@Autowired
private ApplicationContext context;
- private NamingService nacosNamingService;
-
@PostConstruct
public void init() {
Environment env = context.getEnvironment();
- nacosDiscoveryProperties.overrideFromEnv(context.getEnvironment());
- nacosNamingService = nacosDiscoveryProperties.getNamingService();
-
Integer managementPort = ManagementServerPortUtils.getPort(context);
if (null != managementPort) {
Map metadata = nacosDiscoveryProperties.getMetadata();
@@ -124,11 +119,7 @@ public class NacosRegistration implements Registration, ServiceInstance {
}
public NamingService getNacosNamingService() {
- return nacosNamingService;
- }
-
- public void setNacosNamingService(NamingService nacosNamingService) {
- this.nacosNamingService = nacosNamingService;
+ return nacosDiscoveryProperties.namingServiceInstance();
}
public void setNacosDiscoveryProperties(
@@ -139,7 +130,6 @@ public class NacosRegistration implements Registration, ServiceInstance {
@Override
public String toString() {
return "NacosRegistration{" + "nacosDiscoveryProperties="
- + nacosDiscoveryProperties + ", nacosNamingService=" + nacosNamingService
- + '}';
+ + nacosDiscoveryProperties + '}';
}
}
diff --git a/spring-cloud-alibaba-sentinel-datasource/pom.xml b/spring-cloud-alibaba-sentinel-datasource/pom.xml
new file mode 100644
index 000000000..f2878dfe1
--- /dev/null
+++ b/spring-cloud-alibaba-sentinel-datasource/pom.xml
@@ -0,0 +1,69 @@
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-alibaba
+ 0.2.1.BUILD-SNAPSHOT
+
+ 4.0.0
+
+ org.springframework.cloud
+ spring-cloud-alibaba-sentinel-datasource
+ Spring Cloud Alibaba Sentinel DataSource
+
+
+
+
+ com.alibaba.csp
+ sentinel-datasource-extension
+
+
+
+ com.alibaba.csp
+ sentinel-datasource-nacos
+ provided
+ true
+
+
+
+ com.alibaba.csp
+ sentinel-datasource-zookeeper
+ provided
+ true
+
+
+
+ com.alibaba.csp
+ sentinel-datasource-apollo
+ provided
+ true
+
+
+
+
+
+ org.springframework.boot
+ spring-boot
+ provided
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ provided
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/DataSourceLoader.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/DataSourceLoader.java
new file mode 100644
index 000000000..40f17197d
--- /dev/null
+++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/DataSourceLoader.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2018 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.alibaba.sentinel.datasource;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+
+import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX;
+
+/**
+ * {@link ReadableDataSource} Loader
+ *
+ * @author Jim
+ */
+public class DataSourceLoader {
+
+ private static final Logger logger = LoggerFactory.getLogger(DataSourceLoader.class);
+
+ private final static String PROPERTIES_RESOURCE_LOCATION = "META-INF/sentinel-datasource.properties";
+
+ private final static String ALL_PROPERTIES_RESOURCES_LOCATION = CLASSPATH_ALL_URL_PREFIX
+ + PROPERTIES_RESOURCE_LOCATION;
+
+ private final static ConcurrentMap> dataSourceClassesCache
+ = new ConcurrentHashMap>(
+ 4);
+
+ static void loadAllDataSourceClassesCache() {
+ Map> dataSourceClassesMap = loadAllDataSourceClassesCache(
+ ALL_PROPERTIES_RESOURCES_LOCATION);
+
+ dataSourceClassesCache.putAll(dataSourceClassesMap);
+ }
+
+ static Map> loadAllDataSourceClassesCache(
+ String resourcesLocation) {
+
+ Map> dataSourcesMap
+ = new HashMap>(
+ 4);
+
+ ClassLoader classLoader = DataSourceLoader.class.getClassLoader();
+
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+
+ try {
+
+ Resource[] resources = resolver.getResources(resourcesLocation);
+
+ for (Resource resource : resources) {
+ if (resource.exists()) {
+ Properties properties = PropertiesLoaderUtils
+ .loadProperties(resource);
+ for (Map.Entry