小编sva*_*ret的帖子

在 Gradle 构建中,启动 Spring boot 应用程序,运行测试,然后停止 Spring boot 应用程序

通过 Gradle 构建,我想启动 Spring Boot 应用程序,运行一些测试,然后关闭 Spring Boot 应用程序。首先,我尝试启动服务器然后关闭,暂时不进行测试。

我的 build.gradle 文件的一部分如下所示

bootRun {
    systemProperties = System.properties
}

task shutdown(type: org._10ne.gradle.rest.RestTask) {
    httpMethod = 'post'
    uri = 'http://localhost:8080/shutdown'
}

task integrationTest() {
    dependsOn bootRun
    finalizedBy shutdown
}
Run Code Online (Sandbox Code Playgroud)

我像这样从命令行开始构建

gradle integrationTest -Dendpoints.shutdown.enabled=true
Run Code Online (Sandbox Code Playgroud)

构建会启动 Spring Boot 应用程序,但它不会(当然)继续执行关闭任务。我可以单独运行关闭任务,它将关闭 Spring Boot 应用程序。

但是,如何让服务器在同一个构建中运行和关闭?

spring integration-testing gradle spring-boot

6
推荐指数
1
解决办法
2366
查看次数

标签 统计

gradle ×1

integration-testing ×1

spring ×1

spring-boot ×1