Skip to content

Commit

Permalink
feat: wait database on
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzow committed Mar 27, 2023
1 parent 11687e8 commit 55192e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.daw.alist.services;

import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.support.DatabaseStartupValidator;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.stream.Stream;

@SpringBootConfiguration
public class DatabaseWaitConfigurator {

@Bean
public DatabaseStartupValidator databaseStartupValidator(DataSource dataSource) {
DatabaseStartupValidator dsv = new DatabaseStartupValidator();
dsv.setDataSource(dataSource);
dsv.setInterval(5);
dsv.setTimeout(120);
return dsv;
}

@Bean
public static BeanFactoryPostProcessor dependsOnPostProcessor() {
return bf -> {
String[] jpa = bf.getBeanNamesForType(EntityManagerFactory.class);
Stream.of(jpa).map(bf::getBeanDefinition).forEach(it -> it.setDependsOn("databaseStartupValidator"));
};
}

}
3 changes: 3 additions & 0 deletions back/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ server.ssl.key-password=secret
#Only accept HTTPS requests
server.ssl.enabled=true

# Not show database connection error
logging.level.com.zaxxer.hikari=OFF

#JWT config
jwt.header=Authorization
jwt.secret=secret
Expand Down

0 comments on commit 55192e6

Please sign in to comment.