What is the meaning of lazy-initialization in Spring Boot properties file ?

In one of our projects in company. A teammate did this long time ago, and I don't get why ? The property documentation says :
Whether initialization should be performed lazily. - default value is false
spring:
main:
lazy-initialization: true
spring:
main:
lazy-initialization: true
7 Replies
JavaBot
JavaBot7d ago
This post has been reserved for your question.
Hey @FirasRG! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st7d ago
IIRC that should be about bean initialization so if you have
@Component
public class SomeComponent {
@Autowired
private OtherComponent other;
}
@Component
public class SomeComponent {
@Autowired
private OtherComponent other;
}
then lazy initialization allows Spring to create and register SomeComponent before the OtherComponent bean is fully initialized nvm not that it means that if you declare a bean, it will only be created when it's actually needed
FirasRG
FirasRGOP7d ago
so that property makes all beans in the app lazy ?
dan1st
dan1st7d ago
yes
FirasRG
FirasRGOP7d ago
got it and that could harm the app ? :Huh:
dan1st
dan1st7d ago
it can delay errors so if there's something wrong with a bean, the application might still start but cause exceptions in the future with eager initialization, you see these exceptions directly when the applicatio starts up so you immediately know when something is wrong
JavaBot
JavaBot6d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?