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.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 797d28e98..d0a8acb7a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -8,7 +8,7 @@
org.springframework.cloud
spring-cloud-build
- 1.3.10.RELEASE
+ 1.3.11.RELEASE
@@ -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,7 +59,7 @@
- 1.3.3.RELEASE
+ 1.3.5.RELEASE
1.4.4.RELEASE
4.12
@@ -82,6 +86,8 @@
spring-cloud-starter-alicloud
spring-cloud-alicloud-oss
spring-cloud-alicloud-context
+ spring-cloud-alicloud-acm
+ spring-cloud-alicloud-ans
@@ -138,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 bf95c0654..01aeed94b 100644
--- a/spring-cloud-alibaba-dependencies/pom.xml
+++ b/spring-cloud-alibaba-dependencies/pom.xml
@@ -6,7 +6,7 @@
spring-cloud-dependencies-parent
org.springframework.cloud
- 1.3.10.RELEASE
+ 1.3.11.RELEASE
spring-cloud-alibaba-dependencies
@@ -117,7 +117,7 @@
-
+
com.aliyun.oss
aliyun-sdk-oss
@@ -125,7 +125,7 @@
-
+
org.springframework.cloud
spring-cloud-alibaba-sentinel
@@ -151,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}
+
@@ -176,7 +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..4d9bf1d48
--- /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.0.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..28fafb1fd
--- /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.0.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..c2b43b93f
--- /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.0.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..59070f37c
--- /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.0.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/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/pom.xml b/spring-cloud-alibaba-examples/pom.xml
index fbf652077..fad238409 100644
--- a/spring-cloud-alibaba-examples/pom.xml
+++ b/spring-cloud-alibaba-examples/pom.xml
@@ -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-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-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourcePostProcessor.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourcePostProcessor.java
index 40f313700..73ece0ec4 100644
--- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourcePostProcessor.java
+++ b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourcePostProcessor.java
@@ -195,30 +195,44 @@ public class SentinelDataSourcePostProcessor
@EventListener(classes = ApplicationReadyEvent.class)
public void appStartedListener(ApplicationReadyEvent event) throws Exception {
+ logger.info("[Sentinel Starter] Start to find ReadableDataSource");
Map dataSourceMap = event.getApplicationContext().getBeansOfType(
ReadableDataSource.class);
if (dataSourceMap.size() == 1) {
+ logger.info("[Sentinel Starter] There exists only one ReadableDataSource named {}, start to load rules",
+ dataSourceMap.keySet().iterator().next());
ReadableDataSource dataSource = dataSourceMap.values().iterator().next();
Object ruleConfig = dataSource.loadConfig();
SentinelProperty sentinelProperty = dataSource.getProperty();
- if (checkRuleType(ruleConfig, FlowRule.class)) {
+ Integer rulesNum;
+ if ((rulesNum = checkRuleType(ruleConfig, FlowRule.class)) > 0) {
FlowRuleManager.register2Property(sentinelProperty);
+ logger.info("[Sentinel Starter] load {} flow rules", rulesNum);
}
- if (checkRuleType(ruleConfig, DegradeRule.class)) {
+ if ((rulesNum = checkRuleType(ruleConfig, DegradeRule.class)) > 0) {
DegradeRuleManager.register2Property(sentinelProperty);
+ logger.info("[Sentinel Starter] load {} degrade rules", rulesNum);
}
- if (checkRuleType(ruleConfig, SystemRule.class)) {
+ if ((rulesNum = checkRuleType(ruleConfig, SystemRule.class)) > 0) {
SystemRuleManager.register2Property(sentinelProperty);
+ logger.info("[Sentinel Starter] load {} system rules", rulesNum);
}
- if (checkRuleType(ruleConfig, AuthorityRule.class)) {
+ if ((rulesNum = checkRuleType(ruleConfig, AuthorityRule.class)) > 0) {
AuthorityRuleManager.register2Property(sentinelProperty);
+ logger.info("[Sentinel Starter] load {} authority rules", rulesNum);
}
+ } else if (dataSourceMap.size() > 1) {
+ logger.warn(
+ "[Sentinel Starter] There exists more than one ReadableDataSource, can not choose which one to load");
+ } else {
+ logger.warn(
+ "[Sentinel Starter] No ReadableDataSource exists");
}
}
- private boolean checkRuleType(Object ruleConfig, Class type) {
+ private Integer checkRuleType(Object ruleConfig, Class type) {
if (ruleConfig.getClass() == type) {
- return true;
+ return 1;
} else if (ruleConfig instanceof List) {
List ruleList = (List)ruleConfig;
List checkList = new ArrayList();
@@ -228,10 +242,10 @@ public class SentinelDataSourcePostProcessor
}
}
if (ruleList.size() == checkList.size()) {
- return true;
+ return ruleList.size();
}
}
- return false;
+ return -1;
}
class SentinelDataSourceField {
diff --git a/spring-cloud-alicloud-acm/pom.xml b/spring-cloud-alicloud-acm/pom.xml
new file mode 100644
index 000000000..d884d8c4c
--- /dev/null
+++ b/spring-cloud-alicloud-acm/pom.xml
@@ -0,0 +1,71 @@
+
+
+ 4.0.0
+
+
+
+ org.springframework.cloud
+ spring-cloud-alibaba
+ 0.1.0.BUILD-SNAPSHOT
+
+
+ spring-cloud-alicloud-acm
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-alicloud-context
+
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+
+
+
+ com.aliyun
+ aliyun-java-sdk-edas
+
+
+
+ com.alibaba.edas.acm
+ acm-sdk
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ provided
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+ true
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-context
+
+
+ org.springframework.cloud
+ spring-cloud-commons
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java
new file mode 100644
index 000000000..5930568a9
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java
@@ -0,0 +1,73 @@
+/*
+ * 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.alicloud.acm;
+
+import com.taobao.diamond.client.Diamond;
+import org.springframework.beans.BeansException;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.alicloud.acm.endpoint.AcmHealthIndicator;
+import org.springframework.cloud.alicloud.acm.refresh.AcmContextRefresher;
+import org.springframework.cloud.alicloud.acm.refresh.AcmRefreshHistory;
+import org.springframework.cloud.alicloud.context.acm.AcmProperties;
+import org.springframework.cloud.context.refresh.ContextRefresher;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created on 01/10/2017.
+ *
+ * @author juven.xuxb
+ */
+@Configuration
+@ConditionalOnClass({Diamond.class})
+@EnableConfigurationProperties(AcmProperties.class)
+public class AcmAutoConfiguration implements ApplicationContextAware {
+
+ private ApplicationContext applicationContext;
+
+ @Bean
+ public AcmPropertySourceRepository acmPropertySourceRepository() {
+ return new AcmPropertySourceRepository(applicationContext);
+ }
+
+ @Bean
+ public AcmHealthIndicator acmHealthIndicator(AcmProperties acmProperties,
+ AcmPropertySourceRepository acmPropertySourceRepository) {
+ return new AcmHealthIndicator(acmProperties, acmPropertySourceRepository);
+ }
+
+ @Bean
+ public AcmRefreshHistory acmRefreshHistory() {
+ return new AcmRefreshHistory();
+ }
+
+ @Bean
+ public AcmContextRefresher acmContextRefresher(AcmProperties acmProperties, ContextRefresher contextRefresher,
+ AcmRefreshHistory refreshHistory,
+ AcmPropertySourceRepository propertySourceRepository) {
+ return new AcmContextRefresher(contextRefresher, acmProperties, refreshHistory, propertySourceRepository);
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmPropertySourceRepository.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmPropertySourceRepository.java
new file mode 100644
index 000000000..42b84c89f
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmPropertySourceRepository.java
@@ -0,0 +1,68 @@
+/*
+ * 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.alicloud.acm;
+
+import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.CompositePropertySource;
+import org.springframework.core.env.PropertySource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author juven.xuxb, 5/17/16.
+ */
+public class AcmPropertySourceRepository {
+
+ private final ApplicationContext applicationContext;
+
+ public AcmPropertySourceRepository(ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ /**
+ * get all acm properties from application context
+ * @return
+ */
+ public List getAll() {
+ List result = new ArrayList<>();
+ ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) applicationContext;
+ for (PropertySource p : ctx.getEnvironment().getPropertySources()) {
+ if (p instanceof AcmPropertySource) {
+ result.add((AcmPropertySource) p);
+ }
+ else if (p instanceof CompositePropertySource) {
+ collectAcmPropertySources((CompositePropertySource) p, result);
+ }
+ }
+ return result;
+ }
+
+ private void collectAcmPropertySources(CompositePropertySource composite,
+ List result) {
+ for (PropertySource p : composite.getPropertySources()) {
+ if (p instanceof AcmPropertySource) {
+ result.add((AcmPropertySource) p);
+ }
+ else if (p instanceof CompositePropertySource) {
+ collectAcmPropertySources((CompositePropertySource) p, result);
+ }
+ }
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySource.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySource.java
new file mode 100644
index 000000000..3ebae2773
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySource.java
@@ -0,0 +1,55 @@
+/*
+ * 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.alicloud.acm.bootstrap;
+
+import org.springframework.core.env.MapPropertySource;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author juven.xuxb
+ * @author xiaolongzuo
+ */
+public class AcmPropertySource extends MapPropertySource {
+
+ private final String dataId;
+
+ private final Date timestamp;
+
+ private final boolean groupLevel;
+
+ AcmPropertySource(String dataId, Map source, Date timestamp,
+ boolean groupLevel) {
+ super(dataId, source);
+ this.dataId = dataId;
+ this.timestamp = timestamp;
+ this.groupLevel = groupLevel;
+ }
+
+ public String getDataId() {
+ return dataId;
+ }
+
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ public boolean isGroupLevel() {
+ return groupLevel;
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java
new file mode 100644
index 000000000..2bf9cbba3
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java
@@ -0,0 +1,96 @@
+/*
+ * 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.alicloud.acm.bootstrap;
+
+import com.alibaba.edas.acm.ConfigService;
+import com.alibaba.edas.acm.exception.ConfigException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.util.StringUtils;
+
+import java.io.StringReader;
+import java.util.*;
+
+/**
+ * @author juven.xuxb
+ * @author xiaolongzuo
+ */
+class AcmPropertySourceBuilder {
+
+ private Logger logger = LoggerFactory.getLogger(AcmPropertySourceBuilder.class);
+
+ /**
+ * 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象
+ *
+ * @param dataId
+ * @param diamondGroup
+ * @param groupLevel
+ * @return
+ */
+ AcmPropertySource build(String dataId, String diamondGroup, boolean groupLevel) {
+ Properties properties = loadDiamondData(dataId, diamondGroup);
+ if (properties == null) {
+ return null;
+ }
+ return new AcmPropertySource(dataId, toMap(properties), new Date(), groupLevel);
+ }
+
+ private Properties loadDiamondData(String dataId, String diamondGroup) {
+ try {
+ String data = ConfigService.getConfig(dataId, diamondGroup, 3000L);
+ if (StringUtils.isEmpty(data)) {
+ return null;
+ }
+ if (dataId.endsWith(".properties")) {
+ Properties properties = new Properties();
+ logger.info(String.format("Loading acm data, dataId: '%s', group: '%s'",
+ dataId, diamondGroup));
+ properties.load(new StringReader(data));
+ return properties;
+ } else if (dataId.endsWith(".yaml") || dataId.endsWith(".yml")) {
+ YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
+ yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
+ return yamlFactory.getObject();
+ }
+ } catch (Exception e) {
+ if (e instanceof ConfigException) {
+ logger.error("DIAMOND-100500:" + dataId + ", " + e.toString(), e);
+ } else {
+ logger.error("DIAMOND-100500:" + dataId, e);
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map toMap(Properties properties) {
+ Map result = new HashMap<>();
+ Enumeration keys = (Enumeration)properties.propertyNames();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ Object value = properties.getProperty(key);
+ if (value != null) {
+ result.put(key, ((String)value).trim());
+ } else {
+ result.put(key, null);
+ }
+ }
+ return result;
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceLocator.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceLocator.java
new file mode 100644
index 000000000..a7c167619
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceLocator.java
@@ -0,0 +1,69 @@
+/*
+ * 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.alicloud.acm.bootstrap;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.alicloud.context.acm.AcmIntegrationProperties;
+import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
+import org.springframework.core.env.CompositePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.PropertySource;
+
+/**
+ * @author juven.xuxb
+ * @author xiaolongzuo
+ */
+public class AcmPropertySourceLocator implements PropertySourceLocator {
+
+ private static final String DIAMOND_PROPERTY_SOURCE_NAME = "diamond";
+
+ private static String defaultDiamondGroup = "DEFAULT_GROUP";
+
+ private AcmPropertySourceBuilder acmPropertySourceBuilder = new AcmPropertySourceBuilder();
+
+ @Autowired
+ private AcmIntegrationProperties acmIntegrationProperties;
+
+ @Override
+ public PropertySource> locate(Environment environment) {
+
+ CompositePropertySource compositePropertySource = new CompositePropertySource(
+ DIAMOND_PROPERTY_SOURCE_NAME);
+
+ for (String dataId : acmIntegrationProperties.getGroupConfigurationDataIds()) {
+ loadDiamondDataIfPresent(compositePropertySource, dataId, defaultDiamondGroup,
+ true);
+ }
+
+ for (String dataId : acmIntegrationProperties
+ .getApplicationConfigurationDataIds()) {
+ loadDiamondDataIfPresent(compositePropertySource, dataId, defaultDiamondGroup,
+ false);
+ }
+
+ return compositePropertySource;
+ }
+
+ private void loadDiamondDataIfPresent(final CompositePropertySource composite,
+ final String dataId, final String diamondGroup, final boolean groupLevel) {
+ AcmPropertySource ps = acmPropertySourceBuilder.build(dataId, diamondGroup,
+ groupLevel);
+ if (ps != null) {
+ composite.addFirstPropertySource(ps);
+ }
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureAnalyzer.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureAnalyzer.java
new file mode 100644
index 000000000..64d56be39
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureAnalyzer.java
@@ -0,0 +1,40 @@
+/*
+ * 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.alicloud.acm.diagnostics.analyzer;
+
+import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
+import org.springframework.boot.diagnostics.FailureAnalysis;
+
+/**
+ * A {@code FailureAnalyzer} that performs analysis of failures caused by a
+ * {@code DiamondConnectionFailureException}.
+ *
+ * @author juven.xuxb, 07/11/2016.
+ */
+public class DiamondConnectionFailureAnalyzer
+ extends AbstractFailureAnalyzer {
+
+ @Override
+ protected FailureAnalysis analyze(Throwable rootFailure,
+ DiamondConnectionFailureException cause) {
+ return new FailureAnalysis(
+ "Application failed to connect to Diamond, unable to access http://"
+ + cause.getDomain() + ":" + cause.getPort()
+ + "/diamond-server/diamond",
+ "config the right endpoint", cause);
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureException.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureException.java
new file mode 100644
index 000000000..a1b10abf6
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureException.java
@@ -0,0 +1,52 @@
+/*
+ * 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.alicloud.acm.diagnostics.analyzer;
+
+/**
+ * A {@code DiamondConnectionFailureException} is thrown when the application fails to
+ * connect to Diamond Server.
+ *
+ * @author juven.xuxb, 07/11/2016.
+ */
+public class DiamondConnectionFailureException extends RuntimeException {
+
+ private final String domain;
+
+ private final String port;
+
+ public DiamondConnectionFailureException(String domain, String port, String message) {
+ super(message);
+ this.domain = domain;
+ this.port = port;
+ }
+
+ public DiamondConnectionFailureException(String domain, String port, String message,
+ Throwable cause) {
+ super(message, cause);
+ this.domain = domain;
+ this.port = port;
+ }
+
+ String getDomain() {
+ return domain;
+ }
+
+ String getPort() {
+ return port;
+ }
+
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/endpoint/AcmEndpoint.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/endpoint/AcmEndpoint.java
new file mode 100644
index 000000000..1d7876bd6
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/endpoint/AcmEndpoint.java
@@ -0,0 +1,76 @@
+/*
+ * 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.alicloud.acm.endpoint;
+
+import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
+import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
+import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
+import org.springframework.cloud.alicloud.acm.refresh.AcmRefreshHistory;
+import org.springframework.cloud.alicloud.context.acm.AcmProperties;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created on 01/10/2017.
+ *
+ * @author juven.xuxb
+ */
+public class AcmEndpoint extends AbstractEndpoint