首页 > 移动平台 > 详细

Spring boot 梳理 - 在bean中使用命令行参数-自动装配ApplicationArguments

时间:2018-12-31 11:08:28      阅读:213      评论:0      收藏:0      [点我收藏+]

If you need to access the application arguments that were passed to SpringApplication.run(…?), you can inject a org.springframework.boot.ApplicationArguments bean. The ApplicationArguments interface provides access to both the raw String[] arguments as well as parsed option and non-option arguments, as shown in the following example:

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"]
    }

}

 

Spring boot 梳理 - 在bean中使用命令行参数-自动装配ApplicationArguments

原文:https://www.cnblogs.com/jiangtao1218/p/10201531.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!