1

I working on a project which uses Spring boot , Spring Data JPA and postgres .There is a problem that can't solve .

When my application start up ,The database not ready yet . It need to add to application at runtime . But I also want to initialize a database using JPA. just like spring.jpa.hibernate.ddl-auto:create-drop,Unfortunately Initialize a database using JPA will happen at application startup.

My question is that how to delay spring data jpa DDL generation. now we can't add a datasource at application runtime.

I am searching for a long time on net. But no use. The AbstractRoutingDataSource may be not suit for us, because we don't have a datasource at begin . Please help or try to give some ideas how to achieve this

Thanks in advance

tanghuailong
  • 11
  • 1
  • 4

1 Answers1

1

AbstractRoutingDataSource is not useful as it requires pre-configured datasources. just check this stackoverflow question, it shows how you can add/remove datasources at runtime. While it doesn't support hibernate's delayed ddl creation but you can create database tables in runtime datasources using schema.sql and inserts some constants using data.sql.

belnxkkk
  • 375
  • 1
  • 3
  • 11