Tutorial by Examples

@Configuration // @Lazy - For all Beans to load lazily public class AppConf { @Bean @Lazy public Demo demo() { return new Demo(); } }
@Component @Lazy public class Demo { .... .... } @Component public class B { @Autowired @Lazy // If this is not here, Demo will still get eagerly instantiated to satisfy this request. private Demo demo; ....... }
The @Lazy allow us to instruct the IOC container to delay the initialization of a bean. By default, beans are instantiated as soon as the IOC container is created, The @Lazy allow us to change this instantiation process. lazy-init in spring is the attribute of bean tag. The values of lazy-init are...

Page 1 of 1