【发布时间】:2020-04-14 09:12:17
【问题描述】:
我正在阅读一本 Spring Batch 书籍并制作示例,因为我将在下个月开始使用 Java 和 Spring Batch(现在我使用 C#),一个例子使用 ParameterValidator 来验证接收一个参数 @ 987654324@ 所以maven test 只有在参数过去的情况下才会起作用,
public class ParameterValidator implements JobParametersValidator {
@Override
public void validate(JobParameters parameters) throws JobParametersInvalidException {
String fileName = parameters.getString("fileName");
if(!StringUtils.hasText(fileName)) {
throw new JobParametersInvalidException("fileName missing");
}
else if(!StringUtils.endsWithIgnoreCase(fileName, "csv")) {
throw new JobParametersInvalidException("fileName parameter does " +
"not use the csv file extension");
}
}
我尝试使用pom.xml 中的参数标签传递数据:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<arguments> fileName=foo.csv</arguments>
</configuration>
</plugin>
</plugins>
,编辑测试:
并尝试我在互联网上找到的其他答案,但总是会引发缺少参数的错误。
是否可以使用此 IDE 和 maven 传递参数?
谢谢!
【问题讨论】:
-
当我从 cmd 获得 .jar 文件时,我知道如何传递参数,但是当我在 ide 中运行 lyfecycle 时,我无法超越测试,因为它给了我一个错误,我可以不要创造它。
java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: java.lang.IllegalStateException: Failed to execute CommandLineRunner Caused by: org.springframework.batch.core.JobParametersInvalidException: fileName missing我想一定有办法通过在生命周期上编辑测试运行或通过 pom.xml 传递参数但我找不到它
标签: java spring maven intellij-idea