开发辅助-修改配置-static void main(String[] args)

    public static void main(String[] args) throws Exception {
        List<String> argList = new ArrayList<>(Arrays.asList(args));
        argList.add("--redis.ip=localhost");
        argList.add("--mysql.ip=localhost");
        argList.add("--nacos.ip=localhost:8848");
        args = argList.toArray(new String[0]);
        ConfigurableApplicationContext app = SpringApplication.run(SiMdmServerOopApplication.class, args);

        String ip = InetAddress.getLocalHost().getHostAddress();
        Environment env = app.getEnvironment();
        String port = env.getProperty("server.port");
        // & 转义为 ^&
        Runtime.getRuntime().exec("cmd /c start http://" + ip + ":" + port + "/101111004?pageNum=1^&pageSize=10");
    }

 

    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext app = SpringApplication.run(SiMdmServerOopApplication.class, args);

        String ip = java.net.InetAddress.getLocalHost().getHostAddress();
        String port = app.getEnvironment().getProperty("server.port");

        // & 转义为 ^&
        //String url = "http://" + ip + ":" + port + "/101121001?pageNum=1^&pageSize=10";
        String url = "http://" + ip + ":" + port + "/101161001?id=180b0392866dff9c6b228e8d42007622";
        Runtime.getRuntime().exec("cmd /c start " + url);
    }

 

1、args
    public static void main(String[] args) {
        args = new String[]{
                "--server.port=6611",
                "--spring.redis.host=localhost",
                "--spring.datasource.url=jdbc:mysql://localhost:3306/fssuat?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai",
                "--spring.cloud.nacos.discovery.server-addr=localhost:8848"};
        SpringApplication.run(SiMdmServerOopApplication.class, args);
    }
    public static void main(String[] args) {
        args = new String[]{
                "--redis.ip=localhost",
                "--mysql.ip=localhost",
                "--nacos.ip=localhost:8848"};
        SpringApplication.run(SiMdmServerOopApplication.class, args);
    }

 

2、VM options

Edit Configurations

以 “-D” 开头,以 “空格” 间隔。

-Dserver.port=6611 -Dspring.redis.host=localhost -Dspring.cloud.nacos.discovery.server-addr=localhost:8848

 

 

${key:default_value} 这种表达方式是通过key来获取value,如果获取不到就使用后面默认值。

在一些直接通过Jar包启动的场景中,可以在启动时手动配置相关参数,如果没有配置,也会自动获取默认值进行启动。

-Dserver.port=6611 -Dspring.redis.host=localhost -Dspring.cloud.nacos.discovery.server-addr=localhost:8848
或者
-Dserver.port=6611 -Dredis.ip=localhost -Dmysql.ip=localhost -Dnacos.ip=localhost:8848

${redis.ip:10.246.109.97}
${mysql.ip:10.246.109.164}
${nacos.ip:10.247.85.184:8848}

 

posted @ 2022-06-24 09:38  己为  阅读(64)  评论(0编辑  收藏  举报