gpt4 book ai didi

java - 如何在 fork 进程上使用 gradle 任务启动 spring boot 应用程序?

转载 作者:行者123 更新时间:2023-11-30 09:59:29 25 4
gpt4 key购买 nike

我有一个带有虚拟端点的 spring boot 应用程序,我想在其上执行 gatling 负载测试。

渐变任务:

task testLoad(type: JavaExec) {
description = 'Test load the Spring Boot web service with Gatling'
group = 'Load Test'
classpath = sourceSets.test.runtimeClasspath
jvmArgs = [
"-Dgatling.core.directory.binaries=${sourceSets.test.output.classesDir.toString()}",
"-Dlogback.configurationFile=${logbackGatlingConfig()}"
]
main = 'io.gatling.app.Gatling'
args = [
'--simulation', 'webservice.gatling.simulation.WebServiceCallSimulation',
'--results-folder', "${buildDir}/gatling-results",
'--binaries-folder', sourceSets.test.output.classesDir.toString()
]
}

虚拟休息端点:

@RestController
public class GreetingController {
@RequestMapping("/greeting")
public Greeting greeting() {
return new Greeting("Hello, World");
}
}

我想在 gradle 中创建另一个任务,它将启动 spring boot 应用程序。

testLoad.dependsOn startSpringBoot

所以,问题是我不知道如何在 gradle 任务中启动 spring boot 应用程序:

task startSpringBoot(type: JavaExec) {
// somehow start main = 'webservice.Application'
}

然后用另一个任务关闭 spring boot 应用程序:

testLoad.finalizedBy stopSpringBoot


task stopSpringBoot(type: JavaExec) {
// somehow stop main = 'webservice.Application'
}

最佳答案

由于您使用的是 Gradle,因此您可以使用 GradleBuild 任务而不是 JavaExec 任务,如下所示:

task startSpringBoot(type: GradleBuild) {
tasks = ['bootRun']
}

关于java - 如何在 fork 进程上使用 gradle 任务启动 spring boot 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58843292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com