大佬教程收集整理的这篇文章主要介绍了Spring Boot CommandLineRunner:过滤器选项参数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
感谢@AndyWilkinson增强报告,@H_801_3@ApplicationRunner在Spring Boot 1.3.0中添加了接口(目前仍在Milestones中,但我希望很快会发布)
这里是使用它和解决问题的方法:
@H_801_3@@Component public class fileProcessingCommandline implements ApplicationRunner { @OverrIDe public voID run(ApplicationArguments applicationArguments) throws Exception { for (String filename : applicationArguments.getNonoptionArgs()) file file = new file(fileName); service.doSomething(filE); } } }
考虑到Spring Boot @H_801_3@CommandLineRunner应用程序,我想知道如何过滤作为外部化配置传递给Spring Boot的“
switch”选项。
例如,使用:
@H_801_3@@Component public class FileProcessingCommandLine implements CommandLineRunner { @Override public void run(String... Strings) throws Exception { for (String filename: Strings) { File file = new File(fileName); service.doSomething(filE); } } }
我可以打电话@H_801_3@java -jar myJar.jar /tmp/file1 /tmp/file2给这两个文件调用该服务。
但是,如果我添加一个Spring参数,例如@H_801_3@java -jar myJar.jar /tmp/file1 /tmp/file2 --spring.config.name=myproject,配置名称将被更新(正确!),但是该服务也将被请求为文件@H_801_3@./--spring.config.name=myproject(当然不存在)。
我知道我可以手动过滤文件名,例如
@H_801_3@if (!filename.startsWith("--")) ...
但是由于所有这些组件都来自Spring,所以我想知道是否有某个选项可以让它进行管理,并确保@H_801_3@Strings传递给该@H_801_3@run方法的参数在应用程序级别已解析的所有属性选项中均不包含。
以上是大佬教程为你收集整理的Spring Boot CommandLineRunner:过滤器选项参数全部内容,希望文章能够帮你解决Spring Boot CommandLineRunner:过滤器选项参数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。