簡體   English   中英

當spring-boot應用程序需要來自用戶的stdin時,Maven構建暫停

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

我有一個為獨立應用程序創建的簡單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構建的時,構建會在中間暫停,並要求輸入用戶輸入。 這是因為我使用掃描儀來獲取執行的用戶輸入

沒有對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-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);
    }
}

使用-Dmaven.test.skip=true參數構建項目。 問題是,當您運行測試時,所有Spring Context都會運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM