Spring Boot new version i.e. 4.0.4 #190282
-
BodyIn the latest version of Spring Boot, do we have an in-built graceful shutdown? There's one issue in the latest version, and that is the connectivity of MongoDB Compass via application.properties. I guess there's a version mismatch, which causes data not to be saved in the new database and gets saved into the default database named test. All dependencies are downloaded through the official site, which is start.spring.io. Guidelines
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Yes, you can enable graceful shutdown in your application.properties with: Properties How to fix it: Change: spring.data.mongodb.uri To: spring.mongodb.uri Once you update the prefix, Spring will correctly pick up your custom database name. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
|
Yes, graceful shutdown is already built into Spring Boot. In current Spring Boot docs, it’s enabled by default for embedded web servers, so that part does not need custom handling. For MongoDB, the usual fix is to make sure the database name is included in spring.data.mongodb.uri, otherwise MongoDB can fall back to the default test database. The Spring docs still use the spring.data.mongodb prefix, so switching to spring.mongodb.uri is not the right fix here. Example: Also, this is more of a Spring Boot / MongoDB question than a GitHub issue. |
Beta Was this translation helpful? Give feedback.
✅ 1. Graceful shutdown in latest Spring Boot
Yes — modern Spring Boot (2.3+ and fully in 3.x) has built-in graceful shutdown.
You just need to enable it:
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=30s
What it does:
Stops accepting new requests
Waits for active requests to finish
Then shuts down beans (like Mongo connections, thread pools)
👉 So yes, you don’t need custom code anymore — it’s built-in.
This is a very common issue, and you're right — it feels like a version mismatch, but it's usually configuration-related, not dependency mismatch.
🔴 Why data goes to test database?
MongoDB default behavior:
If no database is…