简体   繁体   English

当spring-boot应用程序需要来自用户的stdin时,Maven构建暂停

[英]Maven build pauses when spring-boot application required stdin from user

I have a simple springboot project created for standalone application. 我有一个为独立应用程序创建的简单springboot项目。 Main method implements the run method of ApplicationRunner interface 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);
    }
}

The application can be executed without an issue. 应用程序可以毫无问题地执行。 But when the application is built through maven, the build pauses in the middle and asking for the user input to be entered. 但是当应用程序是通过maven构建的时,构建会在中间暂停,并要求输入用户输入。 It's because I have used the scanner to get the user input for the execution 这是因为我使用扫描仪来获取执行的用户输入

No changes were done to the pom file (It is the default spring-boot pom) 没有对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>

Simple java maven project does not have this issue. 简单的java maven项目没有这个问题。 It builds successfully. 它成功构建。 This only comes with this spring-boot project. 这只是春季启动项目。 What am I doing wrong here? 我在这做错了什么? Do I need to add some kind of a parameter to the spring-boot-maven-plugin 我是否需要在spring-boot-maven-plugin添加某种参数

And I have several unit tests written as well. 我也写了几个单元测试。

@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);
    }
}

Build your project with -Dmaven.test.skip=true arguments. 使用-Dmaven.test.skip=true参数构建项目。 The problem is that when you run the tests, all the Spring Context runs. 问题是,当您运行测试时,所有Spring Context都会运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM