Spring Boot(四)Accessing application arguments

简介: 如果需要访问SpringApplication.run(…​)传入的参数,可以通过注解的形式注入ApplicationArguments接口实例,该接口提供了一套访问String[]参数的方法和【不知道怎么翻译,原文是】as well as parsed option and non-option arguments:import org.

如果需要访问SpringApplication.run(…​)传入的参数,可以通过注解的形式注入
ApplicationArguments接口实例,该接口提供了一套访问String[]参数的方法和【不知道怎么翻译,原文是】as well as parsed option and non-option arguments:

import org.springframework.boot.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;

@Component
public class MyBean {

    @Autowired
    public MyBean(ApplicationArguments args) {
        boolean debug = args.containsOption("debug");
        List<String> files = args.getNonOptionArgs();
        // if run with "--debug logfile.txt" debug=true, files=["logfile.txt"]
    }

}
目录
相关文章
|
6月前
|
缓存 Java Maven
Spring Boot 启动错误:To display the conditions report re-run your application with ‘debug‘ enable —【已解决】
Spring Boot 启动错误:To display the conditions report re-run your application with ‘debug‘ enable —【已解决】
943 1
|
5月前
|
Java Spring
Spring Boot Application in default package
Spring Boot Application in default package
|
Java Spring
Command line is too long. Shorten command line for Application or also for Spring Boot default confi
Command line is too long. Shorten command line for Application or also for Spring Boot default confi
42 1
|
7月前
|
Java Linux Windows
windows解决SpringBoot启动时:APPLICATION FAILED TO START
windows解决SpringBoot启动时:APPLICATION FAILED TO START
318 0
|
Java
【异常】SpringBoot报错Command line is too long.Shorten command line for Application or also for Applicatio
【异常】SpringBoot报错Command line is too long.Shorten command line for Application or also for Applicatio
669 0
|
Java Linux Spring
每日一博 - Spring Boot Application as a Service
每日一博 - Spring Boot Application as a Service
97 0
|
前端开发 Java Spring
Spring MVC框架:第四章:属性域使用(request域、session域、application域)
Spring MVC框架:第四章:属性域使用(request域、session域、application域)
125 0
Spring MVC框架:第四章:属性域使用(request域、session域、application域)
|
Java 应用服务中间件 Spring
SpringBoot Application事件监听的实现方案(动态写入yml)
SpringBoot Application事件监听的实现方案(动态写入yml)
SpringBoot Application事件监听的实现方案(动态写入yml)
|
Java
SpringBoot配置文件application
SpringBoot配置文件application
98 2
springboot配置文件application没有生效处理方式
springboot application.properties不生效(没有生效就是那个文件不是叶子的形态的玩意)