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

亦余心之所善兮,虽九死其犹未悔。这篇文章主要讲述Spring boot 梳理 - 在bean中使用命令行参数-自动装配ApplicationArguments相关的知识,希望能为你提供帮助。
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】 

    推荐阅读