小白们在看这个用例的时候得注意,这个东东不知道他是为了让大家能够快速体验还是怎么的,

反正我一开始没整明白,有点想当然的去理解了;

我一直以为这个Nacos-spring-samples只是一个简单的客户端,跟我之前的自己用例中去调用nacos一样(没有去看他的代码),

但是后面去看的时候有点想当然了,这个Nacos-spring-samples启动的时候触发了一个核心简易的nacos平台,看下他的配置文件

 <listener>
<listener-class>com.alibaba.nacos.embedded.web.servlet.EmbeddedNacosHttpServerListener</listener-class>
</listener>

这个监听服务启动的时候会设置他的系统属性,就是nacos的IP地址加端口号,这个有点牛逼,动态的!

public class EmbeddedNacosHttpServerListener implements ServletContextListener {

    private static final String SERVER_ADDRESS_PROPERTY_NAME = "nacos.server-addr";

    private EmbeddedNacosHttpServer httpServer;

    @Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
if (!System.getProperties().containsKey(SERVER_ADDRESS_PROPERTY_NAME)) {
httpServer = new EmbeddedNacosHttpServer();
httpServer.start(false);
System.setProperty(SERVER_ADDRESS_PROPERTY_NAME, "127.0.0.1:" + httpServer.getPort());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} @Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
if (httpServer != null) {
httpServer.stop();
}
}
}
 public EmbeddedNacosHttpServer start(boolean blocking) {

        httpServer.createContext(path, nacosConfigHttpHandler);

        nacosConfigHttpHandler.init();

        if (blocking) {
startServer();
} else {
future = executorService.submit(new Runnable() {
@Override
public void run() {
startServer();
}
});
} return this;
}
 private void startServer() {
httpServer.start();
String threadName = Thread.currentThread().getName();
System.out.printf("[%s] Embedded Nacos HTTP Server(port : %d) is starting...%n", threadName, port);
System.out.printf("[%s] Embedded Nacos HTTP Server mapped request URI : %s...%n", threadName, path);
}

这样他就启动了一个微缩版的nacos客户端平台,而不是我们通常理解的下面这个平台,之前我一直用下面这个平台的参数去做测试,(# ̄~ ̄#)

提醒大家看的时候不要想当然,多看看代码,把下面这个方法简单的设置下,就可以设置成我们之前想当然的nacos

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
System.setProperty(SERVER_ADDRESS_PROPERTY_NAME, "127.0.0.1:" +"8848"); }

Nacos-spring-samples解析的更多相关文章

  1. Spring源代码解析

    Spring源代码解析(一):IOC容器:http://www.iteye.com/topic/86339 Spring源代码解析(二):IoC容器在Web容器中的启动:http://www.itey ...

  2. Spring源代码解析(收藏)

    Spring源代码解析(收藏)   Spring源代码解析(一):IOC容器:http://www.iteye.com/topic/86339 Spring源代码解析(二):IoC容器在Web容器中的 ...

  3. Spring如何解析Dubbo标签

    1. 要了解Dubbo是如何解析标签的,首先要清楚一点就是Spring如何处理自定义标签的,因为Dubbo的标签可以算是Spring自定义标签的一种情况: 2. Spring通过两个接口来解析自定义的 ...

  4. Spring Security 解析(四) ——短信登录开发

    Spring Security 解析(四) -- 短信登录开发   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security ...

  5. Spring Security 解析(七) —— Spring Security Oauth2 源码解析

    Spring Security 解析(七) -- Spring Security Oauth2 源码解析   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因 ...

  6. Spring Security 解析(六) —— 基于JWT的单点登陆(SSO)开发及原理解析

    Spring Security 解析(六) -- 基于JWT的单点登陆(SSO)开发及原理解析   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把 ...

  7. Spring Security 解析(五) —— Spring Security Oauth2 开发

    Spring Security 解析(五) -- Spring Security Oauth2 开发   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决 ...

  8. Spring Security 解析(三) —— 个性化认证 以及 RememberMe 实现

    Spring Security 解析(三) -- 个性化认证 以及 RememberMe 实现   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把 ...

  9. Spring Security 解析(二) —— 认证过程

    Spring Security 解析(二) -- 认证过程   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...

  10. Spring Security 解析(一) —— 授权过程

    Spring Security 解析(一) -- 授权过程   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...

随机推荐

  1. Git之Eclipse提交项目到Github并实现多人协作

    一.Eclipece提交项目到Github 见  eclipse提交项目到github 二.利用github组织实现多人协作 1.新建组织: New organization

  2. log4j报错ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

    ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only err ...

  3. Android 内存监测工具 DDMS --> Heap

    用 Heap监测应用进程使用内存情况的步骤如下: 1. 启动eclipse后,切换到DDMS透视图,并确认Devices视图.Heap视图都是打开的: 2. 将手机通过USB链接至电脑,链接时需要确认 ...

  4. windows中android SDK manager安装更新sdk很慢,或者出现Done loading packages后不动甚至没有任何可用包

    出现问题: 1.windows中android SDK manager安装更新sdk很慢,或者出现Done loading packages后不动甚至没有任何可用包 2.Failed to fetch ...

  5. 2017-2018-1 20179215《Linux内核原理与分析》第八周作业

    实验:ELF文件格式与程序的编译链接 一.可执行文件的创建  从源代码到可执行程序所要经历的过程概述:  源代码(.c .cpp .h)经过c预处理器(cpp)后生成.i文件,编译器(cc1.cc1p ...

  6. 1045 Favorite Color Stripe (30)(30 分)

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  7. 浅谈Huffman树

    所谓Huffman树,就是叶子结点带权的\(K\)叉树,假设每个叶子的权值为\(v\),到根的距离为\(dep\),那么最小化\(\sum v_i*dep_i\)就是\(Huffman\)树的拿手好戏 ...

  8. [转]Unity3D学习笔记(四)天空、光晕和迷雾

    原文地址:http://bbs.9ria.com/thread-186942-1-1.html 作者:江湖风云 六年前第一次接触<魔兽世界>的时候,被其绚丽的画面所折服,一个叫做贫瘠之地的 ...

  9. JavaScript-Tool:template

    ylbtech-JavaScript-Tool: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http:/ ...

  10. 转载:Android Studio调试功能使用总结

    这段时间一直在使用Intellij IDEA, 今天把调试区工具的使用方法记录于此. 先编译好要调试的程序. 1.设置断点 选定要设置断点的代码行,在行号的区域后面单击鼠标左键即可. 2.开启调试会话 ...