File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
java/es/codeurjc/wallypop/configuration Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
- package es .codeurjc .wallypop .security ;
1
+ package es .codeurjc .wallypop .configuration ;
2
2
3
3
import com .zaxxer .hikari .HikariConfig ;
4
4
import com .zaxxer .hikari .HikariDataSource ;
Original file line number Diff line number Diff line change
1
+ package es .codeurjc .wallypop .configuration ;
2
+
3
+ import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
4
+ import org .springframework .boot .SpringBootConfiguration ;
5
+ import org .springframework .context .annotation .Bean ;
6
+ import org .springframework .jdbc .support .DatabaseStartupValidator ;
7
+
8
+ import javax .persistence .EntityManagerFactory ;
9
+ import javax .sql .DataSource ;
10
+ import java .util .stream .Stream ;
11
+
12
+ @ SpringBootConfiguration
13
+ public class DatabaseWaitConfigurator {
14
+ @ Bean
15
+ public DatabaseStartupValidator databaseStartupValidator (DataSource dataSource ) {
16
+ DatabaseStartupValidator dsv = new DatabaseStartupValidator ();
17
+ dsv .setDataSource (dataSource );
18
+ // Configuration delay and timeout
19
+ dsv .setInterval (5 );
20
+ dsv .setTimeout (120 );
21
+ return dsv ;
22
+ }
23
+ @ Bean
24
+ public static BeanFactoryPostProcessor dependsOnPostProcessor () {
25
+ return bf ->
26
+ {
27
+ // Let beans that need the database depend on the DatabaseStartupValidator
28
+ // like the JPA EntityManagerFactory
29
+ String [] jpa = bf .getBeanNamesForType (EntityManagerFactory .class );
30
+ Stream .of (jpa )
31
+ .map (bf ::getBeanDefinition )
32
+ .forEach (it -> it .setDependsOn ("databaseStartupValidator" ));
33
+ };
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ spring.jpa.properties.hibernate.format_sql=true
16
16
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQL81Dialect
17
17
spring.datasource.hikari.auto-commit =false
18
18
19
+ logging.level.com.zaxxer.hikari =OFF
19
20
20
21
# spring.jpa.properties.hibernate.format_sql=true
21
22
logging.level.org.hibernate.SQL =DEBUG
You can’t perform that action at this time.
0 commit comments