(1)首先需要使用ApplicationArguments
 
package com.helloworld.helloworld;
 
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
 
@RestController
public class HelloController {
//    通过ApplicationArguments传递main方法参数
    @Autowired
    private ApplicationArguments applicationArguments;
    @RequestMapping("/hello")
    public String hello(){
        System.out.println(applicationArguments.getNonOptionArgs());
        return "hello springboot";
    }
}
 
 
 
package com.helloworld.helloworld;
 
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 
import java.util.Arrays;
 
 
@SpringBootApplication
public class HelloworldApplication {
 
 
    public static void main(String[] args) {
        System.out.println(Arrays.toString(args));
        SpringApplication.run(HelloworldApplication.class, args);
    }
 
 
}
 
 
参数修改
参数修改
 
 
(2)使用jar包方式启动
当没有任何参数时
参数修改
当存在参数时
参数修改
(3)使用application.properties
创建application.properties
参数修改
参数修改
参数修改
参数修改
强行修改application.properties名字
参数修改
总结:
参数修改
 

相关文章:

  • 2022-02-06
  • 2021-06-20
  • 2021-09-06
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2022-12-23
  • 2021-06-16
  • 2021-12-22
  • 2021-11-26
  • 2021-08-19
  • 2021-11-24
相关资源
相似解决方案