1

In Spring Boot - is there anyway to only connect to the database when it is required the first time? For example - lazy load the database setup?

I understand this is not the usual pattern but would interested in hearing if there is a solution to this

Thanks Damien

2 Answers 2

1

n Spring Boot - is there anyway to only connect to the database when it is required the first time? For example - lazy load the database setup?

Spring Data and Hibernate can do that setup.

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

2 Comments

thanks for that. I will have a look online for that. If you have any useful links it would be good to see those.
0

I wonder if you can use @Configuration and @Lazy at the same time, and the documentation suggests it is doable but it will create all the bean lazily.

Whereas, if you want to selectively create datasource bean lazily among other beans, then, in that case you need to that use @Lazy on datasource bean

@Configuration
@Lazy
public class YourDataSourceConfigClass {//datasource bean}

1 Comment

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.