Q:

Delay Spring MVC startup with bean "init-method"

My application can't start up, if the PostgreSQL database it's using has not started up yet (the delay between the two is ~2 minutes). It's a fairly complex inherited project and I can't fiddle with the configuration too much.
My idea would be to have a bean that runs as the first thing in the Spring container. I've tried to configure it with annotations (@PostConstruct) and in xml (<bean id="dbStartupMonitor" class="ee.package.monitoring.DBStartupMonitor" init-method="checkConnection" lazy-init="false" />), but in neither of these cases the checkConnection() seems to be running (no logging appears). In addition, how can I make sure that this bean is created first?
Now, regarding the checkConnection(), the idea would be to check if the database is up. If it's not, sleep for some amount of time and try again. This needs to block the rest of the initialization of the Spring MVC container, but I'm pretty sure it doesn't work that way.
Is it even possible to solve it like this?

A:

The problem was the order of bean initialization. The datasource-dependent beans were initialized first, so after some substantial digging in the bean configuration xml files, I added the depends-on attribute with my DB monitor bean. This ensures that the monitor is initialized first.
Also, the initialization method (init-method) does block, so the "check-sleep-check until database is up" cycle works fine.

