Spring contain 2 IOC(Inversion of control) containers which are used to store beans(Objects).
1)Bean factory(Lazy loading)
2)Application context(Eager loading)
these both are Interfaces and the implementation classes of ApplicationContext are 1)ClassPathXmlApplicationContext & 2)AnnotationConfigApplicationContext
⭐ClassPathXmlApplicationContext:
πThis implementation is used to load the Spring beans configuration from XML files located in the classpath.
π It scans the classpath for XML configuration files and initializes the beans defined in those files.
π Example:
ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
⭐AnnotationConfigApplicationContext:
π This implementation is used to load Spring beans configuration from Java-based configuration classes annotated with @Configuration.
πIt scans the packages provided to it for classes annotated with @Configuration, @ComponentScan, @Bean, etc., and initializes the beans based on the configuration provided in these classes.
πExample:
ApplicationContext context=new AnnotationConfigApplicationContext(AppConfig.class);
Comments
Post a Comment