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

17
  • are you talking about production? Commented Aug 16, 2017 at 5:21
  • @AmerQarabsa I am sorry , I can't understand what you means Commented Aug 16, 2017 at 5:28
  • why you want to delay the creation of database? Commented Aug 16, 2017 at 5:30
  • @AmerQarabsa beacause we need a mini project . The database require to add at runtime. Commented Aug 16, 2017 at 5:33
  • @AmerQarabsa The database not ready when The mini project start up Commented Aug 16, 2017 at 5:34

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.