There could be many reasons why a primary goes down: network partition, hardware failures, deliberate stepdown command, among other things. Is there anything in the primary’s logs that could shed a light into why it steps down? What was in the server logs immediately before you observe an error in the application?
Most modern official MongoDB drivers support retryable writes so a topology change should not affect writes too much as it will automatically retry the write once a new primary is elected. Whether the Spring framework supports this feature is perhaps a question for them
This is in Production so need immediate response
Unfortunately the Community Forum does not provide an SLA and might not be the right venue for mission-critical questions needing immediate troubleshooting. For these purposes, you might want to engage MongoDB support that can help you in production situations.