diff --git a/sdk-examples/java/README.md b/sdk-examples/java/README.md
new file mode 100644
index 00000000..e69de29b
diff --git a/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/.gitignore b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/.gitignore
new file mode 100644
index 00000000..7f995f33
--- /dev/null
+++ b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/.gitignore
@@ -0,0 +1,2 @@
+*.iml
+target/
diff --git a/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/README.md b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/README.md
new file mode 100644
index 00000000..5668f06f
--- /dev/null
+++ b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/README.md
@@ -0,0 +1,17 @@
+
+# nacos-spring-boot-config-example 说明
+
+本样例基于 https://github.com/nacos-group/nacos-examples/tree/master/nacos-spring-boot-example/nacos-spring-boot-config-example 修改
+
+
+
+## 使用方式
+
+1. 启动r-nacos
+2. 在public命名空间下增加一个配置, 配置Id: `example` 配置组: `DEFAULT_GROUP` 配置内容:`useLocalCache=true`
+3. 启动spring-boot应用,在本项目目录运行 `mvn spring-boot:run`
+4. 访问应用接口 `curl "http://127.0.0.1:8080/config/get",`请求结果为`true`; 或者直接用浏览器打开`http://127.0.0.1:8080/config/get`
+5. 验证动态修改配置能力,在r-nacos控制台中修改第2步配置内容为`useLocalCache=false`,在第4步请求的结果变更为`false`;
+
+
+
diff --git a/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/pom.xml b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/pom.xml
new file mode 100644
index 00000000..069b17cd
--- /dev/null
+++ b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/pom.xml
@@ -0,0 +1,54 @@
+
+
+ * Nacos 控制台添加配置: + *
+ * Data ID:example + *
+ * Group:DEFAULT_GROUP + *
+ * 配置内容:useLocalCache=true + */ +@SpringBootApplication +@NacosPropertySource(dataId = "example", autoRefreshed = true) +public class NacosConfigApplication { + + public static void main(String[] args) { + SpringApplication.run(NacosConfigApplication.class, args); + } +} diff --git a/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/src/main/java/com/alibaba/nacos/example/spring/boot/controller/ConfigController.java b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/src/main/java/com/alibaba/nacos/example/spring/boot/controller/ConfigController.java new file mode 100644 index 00000000..a85f7e92 --- /dev/null +++ b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/src/main/java/com/alibaba/nacos/example/spring/boot/controller/ConfigController.java @@ -0,0 +1,22 @@ +package com.alibaba.nacos.example.spring.boot.controller; + +import com.alibaba.nacos.api.config.annotation.NacosValue; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import static org.springframework.web.bind.annotation.RequestMethod.GET; + +@Controller +@RequestMapping("config") +public class ConfigController { + + @NacosValue(value = "${useLocalCache:false}", autoRefreshed = true) + private boolean useLocalCache; + + @RequestMapping(value = "/get", method = GET) + @ResponseBody + public boolean get() { + return useLocalCache; + } +} \ No newline at end of file diff --git a/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/src/main/resources/application.properties b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/src/main/resources/application.properties new file mode 100644 index 00000000..530d97ef --- /dev/null +++ b/sdk-examples/java/spring-boot/nacos-spring-boot-config-example/src/main/resources/application.properties @@ -0,0 +1,6 @@ +nacos.config.server-addr=127.0.0.1:8848 + +# endpoint http://localhost:8080/actuator/nacos-config +# health http://localhost:8080/actuator/health +management.endpoints.web.exposure.include=* +management.endpoint.health.show-details=always \ No newline at end of file