The IoC container manages Dependency Injection process and subsequent bean management. Interface BeanFactory provides an advanced configuration.
ApplicationContext is derived from BeanFactory and adds extra functionality:
- Easier integration with Spring AOP
- Message Resource handling
- Event publication
- Application layer specific context, such as WebApplicationContext.
BeanFactory provides configuration framework and configuration while ApplicationContext add more enterprise-specific functionality.
Spring separates application configuration from application objects (beans) and manages these objects by creating them in a correct dependency order and ensuring that they’re fully initialized.
Key principles:
- Don’t repeat yourself
- Separation of concerns
- Convention over configuration
- Testability
Application Context
Application Context interface represents the IoC container and is responsible for instantiating, configuring and assemble the beans. The container gets the information how to configure, assemble and instantiate the beans through metadata.
There are three ways to configure Application Context:
- XML , configure beans and resources using xml files.
- Annotations, annotations configured with autoscan (@Component, @Service, @Repository).
- Java config – also uses annotations @Bean, @Autowired, @Import and a configuration class.
Spring application context can be created in any environment: standalone applications, web application or Junit tests.
Examples of implementation classes: AnnotationConfigApplicationContext, AnnotationConfigWebApplicationContext, XmlWebApplicationContext, ClassPathXmlApplicationContext, FileSystemXMLApplication.
ApplicationContext can receive a file or a class as argument.
https://www.baeldung.com/spring-application-context