M
M
MaxLich2018-10-11 12:14:56
Java
MaxLich, 2018-10-11 12:14:56

What is the default bean initialization in spring 5? Lazy or not?

What is the default initialization of beans in spring 5 using javaConfig and annotations? Lazy or not?
PS And please give a link to the source (preferably the official documentation), where this is clearly written

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2018-10-11
@MaxLich

Hello!
Judging by this answer to the question -
https://stackoverflow.com/questions/15092898/sprin...
The default is no.

The default behavior is false:
By default, ApplicationContext implementations eagerly create and configure all singleton beans as part of the initialization process. Generally, this pre-instantiation is desirable, because errors in the configuration or surrounding environment are discovered immediately, as opposed to hours or even days later. When this behavior is not desirable, you can prevent pre-instantiation of a singleton bean by marking the bean definition as lazy-initialized. A lazy-initialized bean tells the IoC container to create a bean instance when it is first requested, rather than at startup.

I
Iloveski, 2018-10-11
@Iloveski

By default, no. For lazy initialization, there is @Lazy together with bean for lazy initialization of a specific bean, or together with @Configuration for all beans

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question