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
baseURLmethod withbaseUrl(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
- Start your Spring Boot app first: Confirm it’s running on
http://localhost:8080and that the/contactendpoint returns a 200 OK response (test with curl or Postman first). - Execute the Gatling test:
- For Maven: Run
mvn gatling:testfrom your project root - For Gradle: Run
./gradlew gatlingRun
- For Maven: Run
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.portinapplication.properties/application.ymlif you changed it from 8080) - Ensure your Gatling simulation is in the
testsource directory (notmain) - Confirm there are no local firewall rules blocking traffic between Gatling and your Spring Boot app
内容的提问来源于stack exchange,提问作者vallim
相关产品推荐
相关产品推荐

