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

15 messages · Page 1 of 1 (latest)

onyx condor
#

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
nova hearthBOT
#

This post has been reserved for your question.

Hey @onyx condor! 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.

rough vector
#

IIRC that should be about bean initialization

#

so if you have

@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

rough vector
#

it means that if you declare a bean, it will only be created when it's actually needed

onyx condor
rough vector
#

yes

onyx condor
#

got it

#

and that could harm the app ?

rough vector
#

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