diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/pom.xml deleted file mode 100644 index 5c6d8c1a4..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - com.alibaba.cloud - spring-cloud-alibaba-examples - ${revision} - ../../pom.xml - - 4.0.0 - - nacos-config-preference-example - Spring Cloud Starter Alibaba Nacos Config Preference Example - Example demonstrating how to use nacos config preference in spring boot - jar - - - - - org.springframework.boot - spring-boot-starter-web - - - com.alibaba.cloud - spring-cloud-starter-alibaba-nacos-config - - - org.projectlombok - lombok - - - org.springframework.boot - spring-boot-configuration-processor - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - true - - - - - - diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/readme-zh.md b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/readme-zh.md deleted file mode 100644 index c85a4c9fa..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/readme-zh.md +++ /dev/null @@ -1,44 +0,0 @@ -# Nacos Config Preference - -## 项目说明 - -本项目演示如何使用配置偏好配置 - -## 示例 - -1. 启动一个 Nacos server -添加配置 `test.yml` -```yaml -configdata: - user: - name: freeman -``` - -添加配置 `test2.yml` -```yaml -dev: - age: 22 -``` - -2. 设置配置偏好 - -设置默认配置偏好 -```yaml -spring: - cloud: - nacos: - config: - preference: remote -``` - -指定配置(test2.yml)设置配置偏好 -```yaml -spring: - config: - import: - - optional:nacos:test.yml - - optional:nacos:test2.yml?preference=local -``` - -3. 验证 -访问 `localhost`,应该能看到值为 `freeman: 20`,因为 `name` 优先使用了配置中心配置,`age` 优先使用本地配置。 \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/readme.md b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/readme.md deleted file mode 100644 index a7b5296a4..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/readme.md +++ /dev/null @@ -1,44 +0,0 @@ -# Nacos Config Preference - -## Project instruction - -This project demonstrates how to use config preferences. - -## Example - -1. Start a Nacos server -add configuration `test.yml` -```yaml -configdata: - user: - name: freeman -``` - -add configuration `test2.yml` -```yaml -dev: - age: 22 -``` - -2. Set configuration preference - -Set default configuration preference -```yaml -spring: - cloud: - nacos: - config: - preference: remote -``` - -Specify configuration (test 2.yml) to set configuration preference -```yaml -spring: - config: - import: - - optional:nacos:test.yml - - optional:nacos:test2.yml?preference=local -``` - -3. Verify -Access `localhost`, you should see the value of `freeman: 20`, because `name` uses the configuration center configuration first, and `age` uses the local configuration first. \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/ConfigPreferenceApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/ConfigPreferenceApplication.java deleted file mode 100644 index 51963cf9b..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/ConfigPreferenceApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2013-2022 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 - * - * https://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 com.alibaba.cloud.configpreference.examples; - -import com.alibaba.cloud.configpreference.examples.model.UserProperties; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -/** - * @author freeman - */ -@SpringBootApplication -@EnableConfigurationProperties(UserProperties.class) -public class ConfigPreferenceApplication { - - public static void main(String[] args) { - SpringApplication.run(ConfigPreferenceApplication.class, args); - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/controller/UserController.java b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/controller/UserController.java deleted file mode 100644 index 079634d4e..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/controller/UserController.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013-2022 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 - * - * https://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 com.alibaba.cloud.configpreference.examples.controller; - -import com.alibaba.cloud.configpreference.examples.model.UserProperties; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * - * - * @author freeman - */ -@RestController -@RefreshScope -public class UserController { - - @Autowired - private UserProperties userProperties; - @Value("${dev.age}") - private int age; - - @GetMapping - public String getName() { - return userProperties.getName() + ": " + age; - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/model/UserProperties.java b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/model/UserProperties.java deleted file mode 100644 index 63b6eb472..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/java/com/alibaba/cloud/configpreference/examples/model/UserProperties.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2013-2022 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 - * - * https://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 com.alibaba.cloud.configpreference.examples.model; - -import java.util.List; -import java.util.Map; - -import lombok.Data; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * - * - * @author freeman - */ -@Data -@ConfigurationProperties(prefix = "configdata.user") -public class UserProperties { - private String name; - private Integer age; - private Map map; - private List users; - - @Data - public static class User { - private String name; - private Integer age; - } - -} diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/resources/application-dev.yml b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/resources/application-dev.yml deleted file mode 100644 index 3ea6b3fac..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/resources/application-dev.yml +++ /dev/null @@ -1,3 +0,0 @@ -configdata: - user: - name: aa \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/resources/application.yml b/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/resources/application.yml deleted file mode 100644 index 323a9df69..000000000 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-config-preference-example/src/main/resources/application.yml +++ /dev/null @@ -1,31 +0,0 @@ -server: - port: 80 -spring: - application: - name: nacos-config-import-example - cloud: - nacos: - config: - group: DEFAULT_GROUP - server-addr: 127.0.0.1:8848 - preference: remote - config: - import: - - optional:nacos:test.yml - - optional:nacos:test2.yml?preference=local - profiles: - active: dev -logging: - level: - # print content - com.alibaba.cloud.nacos.configdata: debug ---- -spring: - config: - activate: - on-profile: dev -configdata: - user: - name: bb -dev: - age: 20 \ No newline at end of file