Handle mongodb connection issues on startup Handle mongodb connection issues on startup mongodb mongodb

Handle mongodb connection issues on startup


In my searches, I found no good way to make Spring handle this directly. You likely need to put a proxy between your service and the repository. A post here: How to make App server to start even if database is down? approaches this issue.

For you, this probably means having a bean (RepositoryProxy) which Spring creates. This bean will try to create the Mongo connection manually, or get the repository from the application context's lazy bean. If the Mongo connection fails, it catches the exception and creates a connection/object for cached data or error responses. It may also create a timer process to reconnect to the Mongo instance.