一、配置application.properties

#启用鉴权功能
nacos.core.auth.enabled=true

#关闭User-Agent鉴权白名单
nacos.core.auth.enable.userAgentAuthWhite=false

#配置自定义身份识别
nacos.core.auth.server.identity.key=your_key
nacos.core.auth.server.identity.value=your_value

#配置JWT令牌密钥(为了生成JWT令牌,需要配置一个自定义的密钥。注意,原始密钥长度不得低于32字符,且需要进行Base64编码。)
nacos.core.auth.plugin.nacos.token.secret.key=your_secret_key

#配置权限缓存(可选):为了提高性能,可以开启权限缓存。开启后,权限缓存的更新会有一定的延迟。添加以下配置项:
nacos.core.auth.caching.enabled=true

二、spring cluod配置

#在gateway的application.yml文件加
spring:
  cloud:
    nacos:
      discovery:
        username: your_key
        password: your_value
    /**
     * 创建ConfigService
     *
     * @return
     */
    private ConfigService createConfigService() {
        try {
            Properties properties = new Properties();
            properties.setProperty("serverAddr", GatewayRoutersConfiguration.SERVER_ADDR);
            properties.setProperty("namespace", GatewayRoutersConfiguration.NAMESPACE);
            //增加以下账号密码
            properties.setProperty("username", "your_key");
            properties.setProperty("password", "your_value");
            return configService = NacosFactory.createConfigService(properties);
        } catch (Exception e) {
            log.error("创建ConfigService异常", e);
            return null;
        }
    }
#配置项目base-boot-starter\base-boot-starter-cloud的yml文件
spring:
  profiles:
    # 当前激活环境
    active: @profile.name@
  cloud:
    nacos:
      config:
        # Nacos 认证用户
        username: your_key
        # Nacos 认证密码
        password: your_value

GitHub 加速计划 / na / nacos
146
24
下载
Nacos是由阿里巴巴开源的服务治理中间件,集成了动态服务发现、配置管理和服务元数据管理功能,广泛应用于微服务架构中,简化服务治理过程。
最近提交(Master分支:5 个月前 )
4ac42a53 I don't think this default value should be true 4 天前
b4d9642c 7 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐