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/Roadmap-zh.md b/Roadmap-zh.md
index 53ac35f2c..2fc244481 100644
--- a/Roadmap-zh.md
+++ b/Roadmap-zh.md
@@ -15,7 +15,7 @@ Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解
**Nacos**
阿里巴巴开源产品,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
-**Aliyun OSS**
+**AliCloud OSS**
阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
## 即将加入的组件
diff --git a/pom.xml b/pom.xml
index 960ae4c4c..136f3e908 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,13 +8,13 @@
org.springframework.cloud
spring-cloud-build
- 1.3.10.RELEASE
+ 1.3.11.RELEASE
org.springframework.cloud
spring-cloud-alibaba
- 0.1.0
+ 0.1.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,8 +59,8 @@
- 1.3.3.RELEASE
- 1.4.4.RELEASE
+ 1.3.5.RELEASE
+ 1.4.6.RELEASE
4.12
3.0
@@ -73,7 +77,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
@@ -81,6 +85,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
@@ -137,4 +144,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 8fc04cea2..c89ae4889 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
- 1.3.10.RELEASE
+ 1.3.11.RELEASE
spring-cloud-alibaba-dependencies
- 0.1.0
+ 0.1.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
@@ -81,8 +117,7 @@
-
-
+
com.aliyun.oss
aliyun-sdk-oss
@@ -90,12 +125,17 @@
-
+
org.springframework.cloud
spring-cloud-alibaba-sentinel
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-alibaba-sentinel-datasource
+ ${project.version}
+
org.springframework.cloud
spring-cloud-alicloud-oss
@@ -111,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}
+
@@ -136,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..bf731839e
--- /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.1.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..0fa8b5179
--- /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.1.1.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-consumer-feign-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+ org.springframework.cloud
+ spring-cloud-starter-feign
+
+
+ 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..e37fda6e3
--- /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.netflix.feign.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..d1717dd5f
--- /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.netflix.feign.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..467d45390
--- /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,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;
+
+/**
+ * @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..516d4a161
--- /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.1.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..a4ee33d1e
--- /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.1.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 251ab7224..f408c8be7 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.1.0
+ 0.1.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 b9ec18f02..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 直接启动和编译打包后启动。
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 a2f8f3e8f..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.
diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Application.java b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Application.java
index b11681077..1818a2e02 100644
--- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Application.java
+++ b/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Application.java
@@ -16,39 +16,39 @@ import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
}
@Component
class SampleRunner implements ApplicationRunner {
- @Value("${user.name}")
- String userName;
+ @Value("${user.name}")
+ String userName;
- @Value("${user.age}")
- int userAge;
+ @Value("${user.age}")
+ int userAge;
- @Override
- public void run(ApplicationArguments args) throws Exception {
- System.out.println(userName);
- System.out.println(userAge);
- }
+ @Override
+ public void run(ApplicationArguments args) throws Exception {
+ System.out.println(userName);
+ System.out.println(userAge);
+ }
}
@RestController
@RefreshScope
class SampleController {
- @Value("${user.name}")
- String userName;
+ @Value("${user.name}")
+ String userName;
- @Value("${user.age}")
- int age;
+ @Value("${user.age}")
+ int age;
- @RequestMapping("/user")
- public String simple() {
- return "Hello Nacos Config!" + "Hello " + userName + " " + age + "!";
- }
+ @RequestMapping("/user")
+ public String simple() {
+ return "Hello Nacos Config!" + "Hello " + userName + " " + age + "!";
+ }
}
\ No newline at end of file
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 04912e722..038969241 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.1.0
+ 0.1.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 51f025c1f..60847b570 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.1.0
+ 0.1.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 5ca506f5f..151b873f5 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.1.0
+ 0.1.1.BUILD-SNAPSHOT
../../pom.xml
4.0.0
diff --git a/spring-cloud-alibaba-examples/oss-example/pom.xml b/spring-cloud-alibaba-examples/oss-example/pom.xml
index ea01e412a..c48312e02 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.1.0
+ 0.1.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 dd5794d50..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);
- }
- }
- }
-
-}
\ No newline at end of file
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 2da11529e..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();
- }
- }
-
-}
\ No newline at end of file
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..7997ac02e
--- /dev/null
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssApplication.java
@@ -0,0 +1,51 @@
+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-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..97623f5b4
--- /dev/null
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OssController.java
@@ -0,0 +1,70 @@
+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.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 af414af5e..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.security.enabled=false
\ 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/pom.xml b/spring-cloud-alibaba-examples/pom.xml
index 0a5e3e7ce..47a34f4f7 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.1.0
+ 0.1.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 3ba3032b9..e8ffc6852 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.1.0
+ 0.1.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 47b4a51dc..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
@@ -192,9 +192,9 @@ Sentinel 控制台支持实时监控查看,您可以通过 Sentinel 控制台

-## DataSource 支持
+## ReadableDataSource 支持
-Sentinel 内部提供了[动态规则的扩展实现 DataSource](https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9%E5%B1%95#datasource-%E6%89%A9%E5%B1%95)。
+Sentinel 内部提供了[动态规则的扩展实现 ReadableDataSource](https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9%E5%B1%95#datasource-%E6%89%A9%E5%B1%95)。
Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置文件中进行相关配置,即可在 Spring 容器中自动注册 DataSource。
@@ -210,7 +210,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置
然后使用`@SentinelDataSource` 注解修饰 DataSource 即可注入:
@SentinelDataSource("spring.cloud.sentinel.datasource")
- private DataSource dataSource;
+ private ReadableDataSource dataSource;
`@SentinelDataSource` 注解的 value 属性可以不填。默认值就是 `spring.cloud.sentinel.datasource`。
@@ -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
@@ -230,7 +230,7 @@ type目前支持file, nacos, zk, apollo。
1. 定义DataSource
- public class CustomDataSource implements DataSource {
+ public class CustomDataSource implements ReadableDataSource {
private String fieldA;
private String fieldB;
...
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 06e189b9f..157ad0e88 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
@@ -165,9 +165,9 @@ To see the metrics, click **实时监控(Real-time Monitoring)** in the left-sid

-## DataSource
+## ReadableDataSource
-Sentinel provide [DataSource](https://github.com/alibaba/Sentinel/blob/master/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/DataSource.java) to manage dynamic rules.
+Sentinel provide [ReadableDataSource](https://github.com/alibaba/Sentinel/blob/master/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/ReadableDataSource.java) to manage dynamic rules.
Sentinel starter integrated 4 DataSources provided by Sentinel. It will be register into Spring Context if you write some configs in `application.properties`.
@@ -183,7 +183,7 @@ If you want to define FileRefreshableDataSource:
then use `@SentinelDataSource` to annotate DataSource:
@SentinelDataSource("spring.cloud.sentinel.datasource")
- private DataSource dataSource;
+ private ReadableDataSource dataSource;
The value() of `@SentinelDataSource` is not required, it means the prefix of configuration. Default value is `spring.cloud.sentinel.datasource`.
@@ -193,7 +193,7 @@ 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
@@ -201,7 +201,7 @@ User-defined DataSource need 2 steps.
1. Define DataSource
- public class CustomDataSource implements DataSource {
+ public class CustomDataSource implements ReadableDataSource {
private String fieldA;
private String fieldB;
...
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties
index b8ef4539f..b61171907 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties
@@ -10,5 +10,5 @@ spring.cloud.sentinel.datasource.type=file
spring.cloud.sentinel.datasource.recommendRefreshMs=3000
spring.cloud.sentinel.datasource.bufSize=4056196
spring.cloud.sentinel.datasource.charset=utf-8
-spring.cloud.sentinel.datasource.configParser=myParser
+spring.cloud.sentinel.datasource.converter=myParser
spring.cloud.sentinel.datasource.file=/Users/you/rule.json
\ No newline at end of file
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 b8f3dbffd..f27d4059c 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.1.0
+ 0.1.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 30a123bc9..9ecc5ac7d 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.1.0
+ 0.1.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 54feb1b4d..a82708832 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.1.0
+ 0.1.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 85a31d69e..88613d29d 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.1.0
+ 0.1.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 fc0706465..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 file extension yaml support
if (!StringUtils.isEmpty(data)) {
logger.info(String.format("Loading nacos data, dataId: '%s', group: '%s'",
dataId, group));
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 5a020b949..f402acd26 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
@@ -44,15 +44,6 @@ public class NacosConfigEndpointAutoConfiguration {
@Autowired
private NacosPropertySourceRepository nacosPropertySourceRepository;
- @Autowired
- private ConfigService configService;
-
- @Bean
- @ConditionalOnBean
- public NacosConfigProperties nacosConfigProperties() {
- return new NacosConfigProperties();
- }
-
@ConditionalOnMissingBean
@Bean
public NacosConfigEndpoint nacosConfigEndpoint() {
@@ -64,6 +55,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 0b3d82630..ba6688bc5 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
@@ -38,66 +38,57 @@ 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(false).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(false)
+ .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 81466271a..1d0f3e35c 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
@@ -42,6 +42,7 @@ public class NacosConfigBootstrapConfigurationTests {
public void setUp() throws Exception {
this.context = new SpringApplicationBuilder(
NacosConfigBootstrapConfiguration.class).web(false).run(
+ "--spring.application.name=true",
"--spring.cloud.config.enabled=true",
"--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
"--spring.cloud.nacos.config.prefix=myapp");
@@ -67,15 +68,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 cee5c8373..8d8945654 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.1.0
+ 0.1.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 bab4b1a2a..ba1d4ef08 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
@@ -22,12 +22,9 @@ 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,22 +41,11 @@ public class NacosDiscoveryClient implements DiscoveryClient {
@Autowired
private NacosDiscoveryProperties discoveryProperties;
- @Autowired
- private Environment environment;
-
- private NamingService namingService;
-
@Override
public String description() {
return DESCRIPTION;
}
- @PostConstruct
- public void init() {
- discoveryProperties.overrideFromEnv(environment);
- namingService = discoveryProperties.getNamingService();
- }
-
@Override
public ServiceInstance getLocalServiceInstance() {
String serviceId = discoveryProperties.getService();
@@ -73,7 +59,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) {
@@ -113,8 +100,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) {
@@ -124,6 +111,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 dfa1fbb66..ef29eae19 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
@@ -28,7 +28,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
-import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
/**
@@ -43,9 +42,6 @@ public class NacosDiscoveryEndpoint extends AbstractEndpoint