nacos-springboot搭建

1.nacos本地安装版本(版本2.1.0)

安装步骤

  1. nacos官网
  2. 下载地址
  3. 版本选择:版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
  4. 安装:解压即可
  5. 启动:
    cd nacos/bin 目录下
    sh startup.sh -m standalone 启动,standalone代表着单机模式运行,非集群模式
  6. 关闭:sh shutdown.sh
  7. 访问:
    http://localhost:8848/nacos
    用户名/密码 nacos/nacos

2.springboot版本依赖

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

3.nacos版本依赖

		<dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>

4.项目配置

  1. 项目启动类 @EnableDiscoveryClient
    在这里插入图片描述

  2. bootstrap.yml 配置(这里我采用多环境配置,所以只指定了项目名称和环境)

spring:
  application:
    name: init-teplate
  profiles:
    active: dev
  1. bootstrap-dev.yml
    在这里插入图片描述
  2. nacos的配置如下
    在这里插入图片描述

5.动态刷新

  1. 我们在远程的配置文件,添加如下配置信息

在这里插入图片描述

  1. 代码中添加自动刷新注解(@RefreshScope)+获取属性值注解 (@Value(“${XXX.XXX:默认值}”) )

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值