1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

sync & commit in finchley

This commit is contained in:
fangjian0423
2019-10-30 13:10:10 +08:00
parent 6be45914c8
commit 15465b5612
436 changed files with 7099 additions and 3202 deletions

View File

@@ -43,12 +43,10 @@
1. 直接下载:[Nacos Server 下载页](https://github.com/alibaba/nacos/releases)
2. 源码构建:进入 Nacos [Github 项目页面](https://github.com/alibaba/nacos),将代码 git clone 到本地自行编译打包,[参考此文档](https://nacos.io/zh-cn/docs/quick-start.html)。
2. 启动 Server进入下载到本地并解压完成后的文件夹(使用源码构建的方式则进入编译打包好的文件夹),再进去其相对文件夹 nacos/bin并对照操作系统实际情况执行如下命令。[详情参考此文档](https://nacos.io/zh-cn/docs/quick-start.html)。
1. Linux/Unix/Mac 操作系统,执行命令 `sh startup.sh -m standalone`
1. Windows 操作系统,执行命令 `cmd startup.cmd`
2. Windows 操作系统,执行命令 `cmd startup.cmd`
3. 在命令行执行如下命令,向 Nacos Server 中添加一条配置。

View File

@@ -42,12 +42,10 @@ Before we start the demo, let's learn how to connect Nacos Config to a Spring Cl
1. Download: Download Nacos Server [download page](https://github.com/alibaba/nacos/releases)
2. Build from source code: Get source code by git clone git@github.com:alibaba/Nacos.git from Github Nacos and build your code. See [build reference](https://nacos.io/en-us/docs/quick-start.html) for details.
2. Unzip the downloaded file and go to the nacos/bin folder(), And according to the actual situation of the operating system, execute the following command。[see reference for more detail](https://nacos.io/en-us/docs/quick-start.html)。
1. Linux/Unix/Mac , execute `sh startup.sh -m standalone`
1. Windows , execute `cmd startup.cmd`
2. Windows , execute `cmd startup.cmd`
3. Execute the following command to add a configuration to Nacos Server.

View File

@@ -1,5 +1,14 @@
package com.alibaba.cloud.examples;
import java.io.IOException;
import java.io.StringReader;
import java.util.Properties;
import java.util.concurrent.Executor;
import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.listener.Listener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@@ -11,11 +20,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author xiaojing
* @author xiaojing, Jianwei Mao
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@@ -27,13 +35,47 @@ class SampleRunner implements ApplicationRunner {
@Value("${user.name}")
String userName;
@Value("${user.age}")
@Value("${user.age:25}")
int userAge;
@Autowired
private NacosConfigManager nacosConfigManager;
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println(userName);
System.out.println(userAge);
System.out.println(
String.format("Initial username=%s, userAge=%d", userName, userAge));
nacosConfigManager.getConfigService().addListener(
"nacos-config-example.properties", "DEFAULT_GROUP", new Listener() {
/**
* Callback with latest config data.
*
* For example, config data in Nacos is:
*
* user.name=Nacos user.age=25
*
* @param configInfo latest config data for specific dataId in Nacos
* server
*/
@Override
public void receiveConfigInfo(String configInfo) {
Properties properties = new Properties();
try {
properties.load(new StringReader(configInfo));
}
catch (IOException e) {
e.printStackTrace();
}
System.out.println("config changed: " + properties);
}
@Override
public Executor getExecutor() {
return null;
}
});
}
}
@@ -44,7 +86,7 @@ class SampleController {
@Value("${user.name}")
String userName;
@Value("${user.age}")
@Value("${user.age:25}")
int age;
@RequestMapping("/user")