https://github.com/jeeftor/SpringBoot-Dynamic-JarLoad
Spring boot lazy initialization was introduced at 2.2 version.
Sometimes , we might need some of the beans to lazy initialize due to project requirements at the time of application start.
ApplicationContext and
BeanFactory by default lazy loads. It creates the beans only one time and loads when they are called via get method
ApplicationContext loads all the singleton beans upon the startup.
Product2 is eager initialization and Product1 is lazy initialization
2023-03-12T23:53:14.515+05:30 INFO 3726 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 637 ms
Product2 initialized
2023-03-12T23:53:14.612+05:30 INFO 3726 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-03-12T23:53:14.628+05:30 INFO 3726 --- [ main] com.sai.Lazy.LazyApplication : Started LazyApplication in 1.069 seconds (process running for 1.51)
Product1 initialized
Product1 : mac
Product2 : ubuntu