SpringCloud笔记——4.配置中心以及Nacos总结

分布式系统-配置中心 分布式配置中心 阅读详情

忘了补链接了,笔记是根据b站尚硅谷视频写的噢,这次是第十七集到nacos部分完结
在这里插入图片描述

配置中心用来统一管理所有微服务的配置,配置中心可以把修改的配置实时推送给指定的微服务,即使是集群化部署的多个实例节点,也能实时收到变更的配置,从而实现不停机配置更新

基本使用——第十三集

在这里插入图片描述

  • 以订单为例,首先在services的pom引入依赖
<dependency>  
    <groupId>com.alibaba.cloud</groupId>  
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>  
</dependency>
  • 再到order里的配置文件application.properties新增配置
#导入 项目启动后会导入service-order.properties  
spring.config.import=nacos:service-order.properties
  • 现在打开nacos-配置管理-配置列表,点击创建配置
    在这里插入图片描述

  • 数据就是要导入的配置的名字,写完之后发布即可

  • 接下来我们到OrderController进行测试的编写

package com.cg.order.controller;  
  
  
import com.cg.order.bean.Order;  
import com.cg.order.service.OrderService;  
import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.beans.factory.annotation.Value;  
import org.springframework.web.bind.annotation.GetMapping;  
import org.springframework.web.bind.annotation.RequestParam;  
import org.springframework.web.bind.annotation.RestController;  
  
@RestController  
public class OrderController {  
  
    @Autowired  
    OrderService orderService;  
    @Value("${order.timeout}")  
    String orderTimeout;  
    @Value("${order.auto-confirm}")  
    String orderAutoConfirm;  
    //提供一个接口可以返回获取配置的值  
    @GetMapping("/config")  
    public String config(){  
        return "order.timeout"+orderTimeout+";order.auto-confirm"+orderAutoConfirm;  
    }  
  
  
//创建订单  
    //请求映射的路径  
    @GetMapping("/create")  
    public Order createOrder(@RequestParam("userId") Long userId,  
                             @RequestParam("productId") Long productId){  
        Order order = orderService.createOrder(productId, userId);  
        return order;  
    }  
}
  • 然后启动服务进行测试(就是运行OrdeMainApplication.java)

  • 运行后我们在服务发现service-order.properties配置加载成功并且Nacos Config已经开始监听该配置在这里插入图片描述
    在这里插入图片描述

  • 这时候我们去浏览器向8000端口号发送config请求发现得到了配置内容的返回
    在这里插入图片描述

  • 接着我们去nacos里修改配置文件内容后再对config请求界面刷新,发现内容不变,是因为配置属性不会自动刷新。

  • 我们回到OrderController,在OrderController类上新增一个注解==@RefreshScope==,该注解可以实现配置属性的自动刷新。

  • 添加后,重新运行微服务,无论怎么修改配置文件内容,刷新页面后就能得到修改后的内容。在这里插入图片描述

  • 同样的,商品服务也想要用配置中心的话,在有配置中心依赖的情况下,我们没在application.properties配置文件里添加导入配置语句,这时候启动微服务报错在这里插入图片描述

  • 这时候有两种方法,第一种导入可选的nacos配置文件,第二种就是关闭导入检查,这样的话在统一导入了配置中心依赖但暂时不使用配置文件的情况下也能启动微服务。

  • 在application.properties里加入禁用导入检查,这样就可以正常启动微服务了

spring.cloud.nacos.config.import-check.enabled=false

动态刷新——第十四集

在这里插入图片描述

  • 在基本用法中,我们动态刷新用的是@Value获取配置加上@RefreshScope实现自动刷新,但是如果配置属性一旦多的话就会让代码非常繁多重复。
  • 那我们可以把配置用的属性专门放在一个类中,在com.cg.order下新建java类properties.OrderProperties,我们把配置属性复制过去
    OrderProperties:
package com.cg.order.properties;  
  
import lombok.Data;  
import org.springframework.beans.factory.annotation.Value;  
import org.springframework.boot.context.properties.ConfigurationProperties;  
import org.springframework.stereotype.Component;  
  
@Component//@Component 是 Spring 框架中的一个核心注解,用于标记一个类为 Spring 管理的组件。当一个类被 @Component 注解修饰时,Spring 会在组件扫描过程中自动发现并将其注册为应用上下文中的一个 Bean。  
@ConfigurationProperties(prefix = "order")//prefix 前置,这样的话我们属性名就都可以省略order,配置批量绑定在nacos下,可以无需@RefreshScope就能实现自动刷新  
@Data  
public class OrderProperties {  
  
    String timeout;  
  
    String autoConfirm;  
}

OrderController:

package com.cg.order.controller;  
  
  
import com.cg.order.bean.Order;  
import com.cg.order.properties.OrderProperties;  
import com.cg.order.service.OrderService;  
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.RequestParam;  
import org.springframework.web.bind.annotation.RestController;  
  
  
//@RefreshScope //自动刷新配置属性  
@RestController  
public class OrderController {  
  
    @Autowired  
    OrderService orderService;  
  
    @Autowired  
    OrderProperties orderProperties;  
    //提供一个接口可以返回获取配置的值  
    @GetMapping("/config")  
    public String config(){  
        return "order.timeout"+orderProperties.getTimeout()+";order.auto-confirm"+orderProperties.getAutoConfirm();  
    }  
  
  
//创建订单  
    //请求映射的路径  
    @GetMapping("/create")  
    public Order createOrder(@RequestParam("userId") Long userId,  
                             @RequestParam("productId") Long productId){  
        Order order = orderService.createOrder(productId, userId);  
        return order;  
    }  
}
  • 修改完后重启微服务并且修改配置内容再刷新config界面,发现自动刷新成功。

自动刷新总结

利用@Component@ConfigurationProperties将配置属性放在一个类下批量绑定,实现自动刷新且不用@Value获取值。

配置监听NacosConfigManager——第十五集

  • 在订单微服务主程序中新增监听
package com.cg.order;  
  
import com.alibaba.cloud.nacos.NacosConfigManager;  
import com.alibaba.nacos.api.config.ConfigService;  
import com.alibaba.nacos.api.config.listener.Listener;  
import org.springframework.boot.ApplicationArguments;  
import org.springframework.boot.ApplicationRunner;  
import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication;  
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;  
import org.springframework.context.annotation.Bean;  
import org.springframework.web.bind.annotation.GetMapping;  
  
import java.util.concurrent.Executor;  
import java.util.concurrent.Executors;  
  
@EnableDiscoveryClient  
@SpringBootApplication  
public class  OrdeMainApplication {  
    public static void main(String[] args) {  
        SpringApplication.run(OrdeMainApplication.class, args);  
    }  
  
    //1.项目启动就监听配置文件变化  
    //2.发生变化后拿到变化的值  
    //3.发送邮件  
    //ApplicationRunner是spring boot中的一个一次性任务,项目一启动他就会启动  
    @Bean  
    //NacosConfigManager nacosConfigManager实时监听
    ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager) {  
        return args -> {  
            ConfigService configService = nacosConfigManager.getConfigService();  
            //指定数据集"service-order.properties"
            configService.addListener("service-order.properties",  
                    "DEFAULT_GROUP", new Listener() {  
                        @Override  
                        public Executor getExecutor() {//线程池  
                            return Executors.newFixedThreadPool(4);//new一个固定大小为4的线程池  
                        }  
  
                        @Override  
                        public void receiveConfigInfo(String configInfo) {//接收配置信息  
                            System.out.println("变化的配置信息是:"+configInfo);  
                            System.out.println("邮件通知....");  
                        }  
                    });  
            System.out.println("================");  
        };  
    }  
  
  
}
  • 然后重新运行微服务,并修改nacos配置内容重新发布,就可以在控制台看到修改的配置信息在这里插入图片描述

思考题:如果Nacos中的数据集和application.properties有相同的配置项,哪个生效?

以设计的角度,当Nacos中的数据集和application.properties有相同的配置项,以配置中心的为准,这样才能实现快捷的统一管理。
优先级规则:外部导入的优先,后加载者覆盖先加载者。

数据隔离-namespace区分环境——第十七集

在这里插入图片描述

  • 在Nacos中,有一个概念叫Namespace名称空间来区分多套环境,Namespace下又有很多的Group分组,Group又能来区分微服务。比如Group=order,就是订单服务。Group下又有很多的Data-id数据集来区分多种配置。使用Spring Boot激活指定环境来激活配置!在这里插入图片描述

  • 首先,区分多套环境:就是在nacos上新建命名空间在这里插入图片描述

  • 区分多种微服务:在dev空间中的配置列表创建配置,用分组来区分微服务在这里插入图片描述

  • 用克隆快速将dev的两个配置复制到test中,然后继续按照视频操作即可

数据隔离-动态切换环境——第十八集

  • 之前订单的application.properties配置文件是默认读取的public空间的内容,当配置一旦多起来,properties文件看起来就会比较乱。废弃该配置。
  • 在resource中新建一个application.yml文件
server:  
  port: 8000  
spring:  
  application:  
    name: service-order  
# nacos的地址,选择读取的名称空间  
  cloud:  
    nacos:  
      server-addr: 127.0.0.1:8848  
      config:  
        namespace: dev  
  #  config-import可以指定导入的文件但需要选择分组,因为源码中这是一个数组形式,所以可以这么写  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order
  • 接下来在Orderproperties新增String dbUrl;在OrderController加入返回值dbUrl
package com.cg.order.controller;  
  
  
import com.cg.order.bean.Order;  
import com.cg.order.properties.OrderProperties;  
import com.cg.order.service.OrderService;  
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.RequestParam;  
import org.springframework.web.bind.annotation.RestController;  
  
  
//@RefreshScope //自动刷新配置属性  
@RestController  
public class OrderController {  
  
    @Autowired  
    OrderService orderService;  
  
//    @Value("${order.timeout}")  
//    String orderTimeout;  
//    @Value("${order.auto-confirm}")  
//    String orderAutoConfirm;  
    @Autowired  
    OrderProperties orderProperties;  
    //提供一个接口可以返回获取配置的值  
    @GetMapping("/config")  
    public String config(){  
        return "order.timeout"+orderProperties.getTimeout()+";"  
                +"order.auto-confirm"+orderProperties.getAutoConfirm()+";"  
                +"order.db-Url"+orderProperties.getDbUrl();  
    }  
  
  
//创建订单  
    //请求映射的路径  
    @GetMapping("/create")  
    public Order createOrder(@RequestParam("userId") Long userId,  
                             @RequestParam("productId") Long productId){  
        Order order = orderService.createOrder(productId, userId);  
        return order;  
    }  
}
  • 改好后启动微服务访问config在这里插入图片描述
    成功!
  • 接下来我们只需要切换config.namespace就能加载其他的环境
  • 但是假如说我们每个环境加载的配置文件并不一样呢,要如何根据不同的环境加载不同的配置文件
    • 通过多文档模式,用on-profile让配置在指定环境下激活
server:  
  port: 8000  
spring:  
  application:  
    name: service-order  
# nacos的地址,选择读取的名称空间  
  cloud:  
    nacos:  
      server-addr: 127.0.0.1:8848  
      config:  
        namespace: dev  
#yml文件支持多文档模式,就是用---来划分多个文档  
---  
spring:  
  #  config-import可以指定导入的文件但需要选择分组,因为源码中这是一个数组形式,所以可以这么写  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order  
#    on-profile,可以指定在哪种环境生效  
    activate:  
      on-profile: dev  
---  
spring:  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order  
      - nacos:haha.properties?group=order  
    activate:  
      on-profile: test  
---  
spring:  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order  
      - nacos:hehe.properties?group=order  
    activate:  
      on-profile: prod
  • 这么判断当前处于什么环境呢
    • 可以用spring.profiles.active来激活某一个环境
    • 将config.namespace指定加载环境改成 ==${spring.profiles.active:public}==动态取值,如果profiles没配,则取默认值public。
server:  
  port: 8000  
spring:  
  profiles:  
    active: test  
  application:  
    name: service-order  
# nacos的地址,选择读取的名称空间  
  cloud:  
    nacos:  
      server-addr: 127.0.0.1:8848  
      config:  
#       禁用导入检查  
        import-check:  
          enabled: false  
        namespace: ${spring.profiles.active:public}  
#yml文件支持多文档模式,就是用---来划分多个文档  
---  
spring:  
  #  config-import可以指定导入的文件但需要选择分组,因为源码中这是一个数组形式,所以可以这么写  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order  
#    on-profile,可以指定在哪种环境生效  
    activate:  
      on-profile: dev  
---  
spring:  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order  
      - nacos:haha.properties?group=order  
    activate:  
      on-profile: test  
---  
spring:  
  config:  
    import:  
      - nacos:common.properties?group=order  
      - nacos:database.properties?group=order  
      - nacos:hehe.properties?group=order  
    activate:  
      on-profile: prod
  • 再次运行即可在这里插入图片描述
    要是运行失败,可能是空格的原因,冒号后一直要和值有一个空格的距离1
  • 流程就是,首先激活了指定的生产环境标识,然后动态连上配置中心的namespace,然后再判断激活的环境标识属于哪个条件并执行导入。

Nacos总结


·
·
·
·
·
·
·
·
·
·

投了一个月的简历,前几天突然收到两家面试,忙活了半天,大早上起来坐车走路花了快三个小时到,南昌夏天真的很热,出门没几分钟就浑身汗了。毫无意外,经过了不到半小时的拷打,结果不出意外还是让我回去好好沉淀,毕竟八股文什么都没背,一问三不知。虽然没抱希望,但是还是觉得大学生好难阿现在。


  1. yml语法
    yaml使用缩进表示层级关系
    缩进时不允许使用Tab键 只允许使用空格
    且缩进的空格数目并不重要 只要相同层级的元素左侧对齐即可
    属性和值对大小写敏感
    key:(空格)value 表示一对键值对

    注:切记冒号后必须有空格代表属性键值对 否则会识别为一个整体 ↩︎

SpringCloud 配置中心(Nacos)的简单使用 Nacos 是 Spring Cloud Alibaba 核心组件之一,可以用作 Spring Cloud 的注册中心和配置中心,本文重点讲述 Nacos 在SpingCloud 的配置作用。Nacos 的动态配置消除了配置变更时重新部署应用和服务的需要,让配置管理变得更加高效和敏捷,配置中心化管理让实现无状态服务变得更简单,让服务按需弹性扩展变得更容易。... 阅读详情

相关推荐

SpringCloud Alibaba系列 Nacos(一)

springcloud nacos nacos注册中心 nacos配置中心 nacos配置mysql数据源 nacos开启鉴权

原名又逢乱世。不要放下学习的脚步,毕竟比天天打牌、钓鱼、打游戏更能从内在充实自己。 5674

Apollo配置中心教程、详解

Apollo(阿波罗)是一款可靠的分布式配置管理中心,诞生于携程框架研发部,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。Java客户端不依赖任何框架,能够运行于所有Java运行时环境,同时对Spring/Spring Boot环境也有较好的支持。

black_pp的博客 1万+

SpringCloud Alibaba - Nacos 注册发现、分级模型、配置集群、环境隔离、原理

nacos 默认配置端口为 8848,如果你电脑上的 8848 端口被占用,那么就可以对 nacos 端口信息进行配置~c)修改完后点击确定,就完成啦,可以达到这样一个效果——使得端口为 8081 的服务访问频率是端口号为 8082 的服务访问频率的十分之一!服务调用尽可能选择本地集群的服务,跨集群调用延迟较高,当本地集群不可访问时,再去访问其它集群。前面我们提到 Nacos 的服务分级模型,他会优先访问本地集群,实际上这也是需要进行配置的~

CYK_byte的博客 6960

SpringCloud - Nacos详解

1、概述 服务发现是微服务架构体系中最关键的组件之一。如果尝试用手动的方式来给每一个客户端来配置所有服务提供者的服务列表是一件非常困难的事,而且也不利于服务的动态扩缩容。 Nacos Discovery 可以帮助您将服务自动注册到 Nacos 服务端并且能够动态感知和刷新某个服务实例的服务列表。 除此之外,Nacos Discovery 也将服务实例自身的一些元数据信息-例如 host,port, 健康检查URL,主页等内容注册到 Nacos。 2、注册中心原理 在使用注册中心时,一共有三种角色:服务提供者

java123456111的博客 2万+

单细胞分析实战:用R语言绘制带连线的堆叠柱状图(附完整代码)

本文详细介绍了如何使用R语言绘制带连线的堆叠柱状图进行单细胞转录组数据分析,特别适用于展示细胞比例变化趋势。通过完整代码示例和实战技巧,帮助研究者优化多组别比较的可视化效果,提升科研图表质量。

yhn4567890的博客 394

利用Spm12进行fMRI数据分析:从预处理到结果解读的完整指南

本文提供了利用SPM12进行fMRI数据分析的完整流程指南,涵盖从数据预处理、统计建模到结果解读的全过程。详细介绍了在MATLAB环境下使用SPM12图形界面完成头动矫正、空间标准化等关键步骤的操作方法与避坑技巧,帮助神经科学研究者和心理学研究者高效处理功能磁共振成像数据并产出可靠结果。

weixin_29079671的博客 456

2025最新 SpringCloud 教程,创建微服务项目,笔记04

2025最新 SpringCloud 教程,创建微服务项目,笔记04

道友 326

智能车竞赛卡丁快跑组:自动驾驶与人车交互技术实战解析

本文深入解析了智能车竞赛卡丁快跑组的技术核心,重点探讨了自动驾驶与人车交互两大模块的实战方案。文章详细拆解了从环境感知、路径规划到语音识别、命令执行的完整流程,并分享了基于单片机平台的调试心法与赛场经验,为参赛者提供了一套从零开始、分步攻坚的系统性备赛指南。

f0g1h2的博客 1189

SpringCloud-搭建Nacos配置中心

本文详细介绍了如何在Spring Cloud项目中使用Nacos实现配置管理。首先,通过简洁的步骤指导了Nacos的安装和配置。然后,通过在项目中引入Nacos的依赖和配置,实现了与Nacos配置中心的连接。在Nacos控制台上演示了如何新建配置,并通过Spring Cloud项目实现了动态读取配置的操作。这种灵活的配置管理方案为微服务架构提供了高度可维护性和实时性的优势,使得项目能够在运行时动态调整配置,而无需重启服务

踏雨歌青春,诗酒趁年华 5812

DeepBSA实战指南:从安装到基因组分析的全流程解析

本文详细解析了DeepBSA工具从安装到基因组分析的全流程,特别介绍了其简化生物信息学分析的'一键式'操作和独家深度学习算法。通过实战案例展示了DeepBSA在信噪比处理和QTL定位上的优势,并提供了Linux和Windows系统的安装避坑指南、数据预处理技巧以及算法选择建议,帮助用户高效完成基因组分析。

weixin_28732953的博客 454

基于Simulink的MIMO-OFDM系统仿真建模示例

MIMO概述MIMO技术利用多个天线进行信号发送和接收,通过空间复用来提高数据传输速率,或通过空间分集来增强信号的可靠性。OFDM概述OFDM是一种将高速率数据流分成多个低速数据流并行传输的技术,每个子载波都采用调制方式(如BPSK、QPSK),并通过IFFT/FFT变换实现串并转换。MIMO-OFDM优势结合了MIMO的空间分集增益与OFDM对抗多径效应的能力,适用于宽带无线通信系统。提供了更高的数据速率和更好的频谱效率,是现代无线通信标准(如4G LTE、5G NR等)的核心技术之一。

xiaoheshang_123的博客 333

【Nacos】Nacos配置中心的使用与SpringCloud整合

官方文档: https://github.com/alibaba/spring-cloud-alibaba/wiki/Nacos-configNacos提供用于存储配置和其他元数据的key/value存储,为分布式系统中的外部化配置提供服务器端和客户端支持。使用Spring Cloud Alibaba Nacos Config组件,您可以在Nacos Server集中管理你Spring Cloud应用的外部属性配置。用于进行租户粒度的配置隔离。

morris 4万+

前沿探索:基于强化学习的目标检测与跟踪技术及论文解析

前沿探索:基于强化学习的目标检测与跟踪技术及论文解析 ,人工智能,计算机视觉,大模型,AI,本文聚焦基于强化学习的目标检测与跟踪技术,先介绍相关技术基础,包括目标检测、跟踪及强化学习的算法等。接着阐述强化学习在目标检测与跟踪中的应用思路、框架及典型算法,解析三篇相关论文的背景、方法、实验结果。还探讨了该技术面临的样本效率、奖励函数设计等挑战,以及结合迁移学习等的未来发展方向,为该领域研究提供参考。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 11万+

SpringCloud整合Nacos实现配置中心

通过 Nacos Server 和 spring-cloud-starter-alibaba-nacos-config 实现配置的动态变更。 还是以iot-usercenter服务为例进行讲解(iot-common步骤一样,不再赘述)。

supersolon的专栏 1万+

【EB-03】 AUTOSAR builder与EB RTE集成

打开EB工具后,在EB的步骤是:执行MultiTask(2)-> Mapping Component to Partitions(4)->Task Mapping(5)-> SvcAs_Trigger(7)-> Code Generation(8)如涉及新增BSW Module,也需要重复以上步骤。

libuping2023的博客 975

智能车图像处理3-入门级分析2 ---直道冲刺

PS :入门级文章适合新手,如果已经有基础可以去看进阶篇文章。

taiyuezyh的博客 4338

Nacos(四):SpringCloud项目中接入Nacos作为配置中心

前言 通过前两篇文章: Nacos(二):Nacos与OpenFeign的对接使用 Nacos(三):SpringCloud项目中接入Nacos作为注册中心 相信大家已经对Nacos作为注册中心的基本使用已经有了一定的了解。 然而,Nacos远远不止于此,本文我们来看一下Nacos作为配置中心在SpringCloud中的使用 我的环境 Windows10 JDK8 SpringCloud:F...

LarsCheng's Blog 8088

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【SpringCloud】Nacos配置中心

配置中心就是对这些配置项进行统⼀管理。通过配置配置中,可以集中查看,修改和删除配置,无需再逐个修改配置文件。提高效率的同时,也降低了出错的风险。

程序猿教你打篮球的博客 8100

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

SpringCloud Alibaba Nacos 服务注册和配置中心

介绍SpringCloud Alibaba Nacos 服务注册和配置中心

快乐的小三菊的博客 1181

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

SpringCloud - Nacos注册/配置中心

Nacos /nɑ:kəʊs/ 是 DynamicNaming andCoService的首字母简称,一个更易于构建云原生应用的动态服务发现配置管理和服务管理平台。

2201_75490194的博客 1441

SpringCloud篇(配置中心 - Nacos)

这样,UserApplication(8081)使用的profile是dev,UserApplication2(8082)使用的profile是test。{spring.profiles.active}.${spring.cloud.nacos.config.file-extension}作为文件。Nacos一方面可以将配置集中管理,另一方可以在配置变更时,及时通知微服务,实现配置的热更新。我们最终的目的,是修改nacos中的配置后,微服务中无需重启即可让配置生效,也就是。

2312

springcloud整合nacos配置中心

如果大家对相关文章感兴趣,可以关注公众号"架构殿堂",会持续更新AIGC,java基础面试题, netty, spring boot,spring cloud等系列文章,一系列干货随时送达!

Venus's Blog 7万+

SpringCloud配置中心Nacos

Spring Cloud Config为分布式系统的外部配置提供了服务端和客户端的支持方案。在配置的服务端您可以在所有环境中为应用程序管理外部属性的中心位置。客户端和服务端概念上的SpringEnvironment 和 PropertySource 抽象保持同步,它们非常适合Spring应用程序,但是可以与任何语言中运行的应用程序一起使用。当应用程序在部署管道中从一个开发到测试直至进入生产时,您可以管理这些环境之间的配置,并确保应用程序在迁移时具有它们需要运行的所有内容。

daai5201314的博客 4259

SpringCloud学习笔记 - Nacos配置中心搭建 - Nacos Config

Nacos 提供用于存储配置和其他元数据的 key/value 存储,为分布式系统中的外部化配置提供服务器端和客户端支持。使用 Spring Cloud Alibaba Nacos Config,您可以在 Nacos Server 集中管理你 Spring Cloud 应用的外部属性配置。

QIANG_HAO的博客 2787

SpringCloud Nacos 作为Config配置中心,SpringCloud Nacos 配置动态更新

SpringCloud Nacos 作为Config配置中心,SpringCloud Nacos 配置动态更新 ================================ ©Copyright 蕃薯耀2021-03-29 https://www.cnblogs.com/fanshuyao/ 一、SpringCloud Nacos 概述Nacos 是一个 Alibaba 开源的、易于构建云...

蕃薯耀的博客 4663

【SpringCloud Alibaba笔记】(2)Nacos服务注册与配置中心

一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台

jinx 1827
上一篇: SpringCloud笔记——3.远程调用、负载均衡、注册中心总结
下一篇: SpringCloud笔记——5.OpenFeign远程调用
hipguo
博客等级 码龄4年 58粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值