You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gatling与SpringBoot 2.0.1.RELEASE集成异常求助

Troubleshooting Gatling Integration with Spring Boot 2.0.1.RELEASE

Let’s break down what’s going wrong here and get your load test up and running smoothly.

1. Fix the Incomplete Gatling Simulation Script

Your current ContactSimulation has a syntax gap and missing HTTP request details—this is the most immediate issue. Here’s the corrected, fully functional version:

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class ContactSimulation extends Simulation {
    // Configure base URL for your Spring Boot app (note: baseURL is deprecated, use baseUrl)
    val httpConf = http.baseUrl("http://localhost:8080")

    // Define the test scenario: hit the /contact endpoint
    val scn = scenario("GetContact")
        .exec(
            http("Retrieve Contact Endpoint")
                .get("/contact")
                .check(status.is(200)) // Validate we get a successful 200 response
        )

    // Set up load profile (adjust numbers based on your testing needs)
    setUp(
        scn.inject(
            atOnceUsers(10), // Simulate 10 users hitting the endpoint simultaneously
            rampUsers(50) during (10 seconds) // Gradually ramp up to 50 users over 10 seconds
        ).protocols(httpConf)
    )
}

Key fixes here:

  • Completed the HTTP request definition with .get("/contact") and added a response check to confirm success
  • Replaced the deprecated baseURL method with baseUrl (compatible with Gatling 3.x, the recommended version for Spring Boot 2.x)
  • Added a basic load profile so you can actually simulate meaningful traffic

2. Ensure Correct Gatling Dependencies in Your Build

You need to add Gatling’s core libraries and build plugin to your project. Here’s how to set this up for Maven and Gradle:

Maven (pom.xml)

<dependencies>
    <!-- Gatling Core -->
    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-core</artifactId>
        <version>3.9.5</version>
        <scope>test</scope>
    </dependency>
    <!-- Gatling HTTP for API testing -->
    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-http</artifactId>
        <version>3.9.5</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <!-- Gatling Maven Plugin to run tests -->
        <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
            <version>3.9.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Gradle (build.gradle)

plugins {
    id 'io.gatling.gradle' version '3.9.5'
}

dependencies {
    testImplementation 'io.gatling:gatling-core:3.9.5'
    testImplementation 'io.gatling:gatling-http:3.9.5'
}

3. Run the Load Test Properly

  1. Start your Spring Boot app first: Confirm it’s running on http://localhost:8080 and that the /contact endpoint returns a 200 OK response (test with curl or Postman first).
  2. Execute the Gatling test:
    • For Maven: Run mvn gatling:test from your project root
    • For Gradle: Run ./gradlew gatlingRun

After the test completes, Gatling will generate a detailed HTML report in target/gatling (Maven) or build/reports/gatling (Gradle)—open this in a browser to analyze request times, success rates, and more.

4. Quick Additional Checks

  • Double-check your Spring Boot app’s port (look for server.port in application.properties/application.yml if you changed it from 8080)
  • Ensure your Gatling simulation is in the test source directory (not main)
  • Confirm there are no local firewall rules blocking traffic between Gatling and your Spring Boot app

内容的提问来源于stack exchange,提问作者vallim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:03:18