Reputation: 585
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
Upvotes: 1
Views: 1292
Reputation: 555
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}
Upvotes: 0
Reputation: 1321
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.
Upvotes: 1