配置HTTP端点关闭Spring Boot应用失败,请求排查配置问题
Troubleshooting and Fixes for Your Spring Boot Graceful Shutdown Issue
Let's tackle both your local curl problem and the Jenkins NoClassDefFoundError one by one:
1. Fix the Maven Dependency Plugin Misconfiguration (Resolves Jenkins Error)
You've incorrectly added the maven-dependency-plugin as a project dependency in your <dependencies> section. This is a Maven build plugin, not a runtime dependency, so it belongs under <build><plugins> instead. Having it in dependencies can mess up your jar's dependency structure, leading to missing classes at runtime (which is exactly what's happening in Jenkins).
Update your pom.xml like this:
<build> <finalName>AllergiesConditions</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <!-- Move the dependency plugin here --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.2</version> <!-- Add executions here if you need specific plugin goals, like copy-dependencies --> </plugin> </plugins> </build>
Don't forget to delete the maven-dependency-plugin entry from your <dependencies> block.
2. Disable Actuator Security (Fixes Local Curl No-Response Issue)
In Spring Boot 1.5.x, management.security.enabled defaults to true. Even though you set endpoints.shutdown.sensitive=false, the security layer still blocks unauthenticated requests to the shutdown endpoint. That's why your local curl call does nothing— the server is returning a 401 Unauthorized response, but your log setup isn't showing it.
Add this line to your application.properties:
management.security.enabled=false
This will allow unauthenticated POST requests to trigger the shutdown endpoint.
3. Quick Additional Checks
- Verify your local server is actually listening on port 8000: Use
lsof -i :8000(Linux/macOS) ornetstat -ano | findstr "8000"(Windows) to confirm. - Double-check your log configuration: Since you switched to log4j2, make sure your log4j2 config file (e.g.,
log4j2.xml) is insrc/main/resourcesand set to a verbose enough level (likeDEBUG) to see endpoint request details. - Re-package after fixes: Run
mvn clean packageto ensure all dependencies are correctly bundled into your jar, especially after fixing the plugin configuration.
After making these changes, re-deploy your app. The local curl -X POST localhost:8000/shutdown should gracefully stop the server, and the Jenkins NoClassDefFoundError should be gone.
内容的提问来源于stack exchange,提问作者Naveen Kumar

