Spring provides multiple implementations of ApplicationContext to load the various styles of configuration file. These are listed next:
- For Java configuration, the following is used:
ApplicationContext context = new
AnnotationConfigApplicationContext(AppConfig.class);
- For XML configuration, the implementation is as follows:
ApplicationContext context = new
ClassPathXmlApplicationContext("applicationContext.xml");
In the preceding codes, Spring loads the Java configuration files by using the AnnotationConfigApplicationContext class, and the XML configuration files by using the ClassPathXmlApplicationContext class for the Spring container. Spring behaves the same for all types of configuration. It does not matter what configuration styles you use in your application. The following diagram shows what exactly happens in this phase:
As you can see in the preceding diagram, the initialization phase is divided into these two steps:
- Load bean definitions
- Initialize bean instances