nacos学习

java -jar 命令行替换参数

修改入口类,添加args,
在run里面添加args参数即可完成参数化启动。
application.run(args);

例如:

public class HelloworldApp {
    public static void main(String[] args) {

        SpringApplication application = new SpringApplication(MxskETLApp.class);
        application.setBannerMode(Banner.Mode.OFF);
        application.run(args);
        log.info("xxxx Server Starting Successfully !");
    }

参数化启动java

java -jar  xxxx.jar  --spring.profiles.active=dev

也可以指定其他参数

java -jar xxxx.jar --spring.profiles.active=dev   --spring.cloud.nacos.discovery.server-addr=xxxxx:8848 --spring.cloud.nacos.config.server-addr=xxxxxxx:8848 --spring.cloud.nacos.config.namespace=data-dev  --spring.cloud.nacos.discovery.namespace=data-dev

nacos 简单配置

spring:
  application:
    name: hello-service
  profiles:
    active: dev
  group: hello-world-service
  cloud:
    nacos:
      config:
        prefix: ${spring.application.name}-${spring.profiles.active}
        file-extension: properties
        namespace: dev
        group: ${spring.group}
        server-addr: 192.168.1.201:8848
      discovery: 
        group: ${spring.group} 
        namespace: dev  

因为我重定义了prefix,获取配置文件dataid会根据变量获取。
例如,

  • ${spring.profiles.active} 启动参数为–spring.profiles.active=dev,则会获取
    hello-service-dev.properties配置文件
  • ${spring.profiles.active} 启动参数为–spring.profiles.active=test,则会获取
    hello-service-test.properties配置文件
  • ${spring.profiles.active} 启动参数为–spring.profiles.active=prod,则会获取
    hello-service-prod.properties配置文件

Spring Cloud 系列之 Alibaba Nacos 配置中心

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少陽君

谢谢老板的拿铁

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值