diff --git a/ui/resources/application.properties b/ui/resources/application.properties index 07c0935..cbde716 100644 --- a/ui/resources/application.properties +++ b/ui/resources/application.properties @@ -3,6 +3,7 @@ logging.level.org.apache.tika.parser=error logging.level.org.apache.fontbox=error logging.level.org.apache.pdfbox=error logging.level.org.vibur=warn +logging.level.org.springframework.jdbc.support.DatabaseStartupValidator=debug # Management actuators management.endpoints.web.exposure.include=loggers diff --git a/ui/src/bamboo/config/DatabaseStartupConfig.java b/ui/src/bamboo/config/DatabaseStartupConfig.java new file mode 100644 index 0000000..2dbe246 --- /dev/null +++ b/ui/src/bamboo/config/DatabaseStartupConfig.java @@ -0,0 +1,29 @@ +package bamboo.config; + +import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.support.DatabaseStartupValidator; + +import javax.sql.DataSource; +import java.util.concurrent.TimeUnit; + +@Configuration +public class DatabaseStartupConfig { + @Bean + public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) { + var validator = new DatabaseStartupValidator(); + validator.setDataSource(dataSource); + validator.setTimeout((int) TimeUnit.DAYS.toSeconds(7)); + return validator; + } + + /** + * This makes EntityManagerFactory depend on DatabaseStartupValidator to block startup + * until the database is ready. + */ + @Bean + public static EntityManagerFactoryDependsOnPostProcessor databaseStartupDependency() { + return new EntityManagerFactoryDependsOnPostProcessor("databaseStartupValidator"); + } +}