我有一个为独立应用程序创建的简单的springboot项目。Main方法实现ApplicationRunner接口的run方法
@SpringBootApplication
public class DemoApplication implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
public void run(ApplicationArguments args) throws Exception {
final Scanner scanner = new Scanner(System.in);
final String inputFilePath = scanner.nextLine();
System.out.println(inputFilePath);
}
}该应用程序可以在没有问题的情况下执行。但是当通过maven构建应用程序时,构建过程会在中间暂停,并要求输入用户输入。这是因为我使用了scanner来获取执行所需的用户输入
没有对pom文件做任何更改(它是默认的spring-boot pom)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>简单的java maven项目没有这个问题。它成功构建。这只是这个spring-boot项目附带的。我在这里做错了什么?我是否需要向spring-boot-maven-plugin添加某种类型的参数
我还编写了几个单元测试。
@RunWith(SpringRunner.class)
@SpringBootTest
public class ValidationTest {
@Autowired
private ValidationService validationService;
@Test
public void test_1() {
final String number = "8801673191614";
boolean result = validationService.isValidMSISDN(number);
Assert.assertTrue(result);
}
}发布于 2019-05-16 14:11:52
使用-Dmaven.test.skip=true参数构建项目。问题是,当您运行测试时,所有Spring上下文都会运行。
https://stackoverflow.com/questions/56161692
复制相似问题