Delete redundant examples
parent
9ca591585f
commit
1210837331
@ -1,55 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
|
||||||
<version>${revision}</version>
|
|
||||||
<relativePath>../../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>nacos-config-preference-example</artifactId>
|
|
||||||
<name>Spring Cloud Starter Alibaba Nacos Config Preference Example</name>
|
|
||||||
<description>Example demonstrating how to use nacos config preference in spring boot</description>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
|
||||||
<version>${maven-deploy-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<skip>true</skip>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
@ -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.
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -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<String, Object> map;
|
|
||||||
private List<User> users;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class User {
|
|
||||||
private String name;
|
|
||||||
private Integer age;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
configdata:
|
|
||||||
user:
|
|
||||||
name: aa
|
|
@ -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
|
|
Loading…
Reference in New Issue