In Spring Framework we can choose the type of application context from the image below:

But which one is implemented by default by spring boot?
Does it depend on which starter dependencies we choose when create project?
In Spring Framework we can choose the type of application context from the image below:

But which one is implemented by default by spring boot?
Does it depend on which starter dependencies we choose when create project?
It depends on the starter projects you use. For regular projects Spring Boot uses the AnnotationConfigApplicationContext and for web projects the AnnotationConfigServletWebServerApplicationContext.
See also the output of
@SpringBootApplication
public class DummyApplication implements ApplicationContextAware {
public static void main(String[] args) {
SpringApplication.run(DummyApplication.class, args);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
System.out.println(applicationContext.getClass().getName());
}
}
Technically it does not directly depends on the starter , but depends on the value of WebApplicationType you configure to run the application :
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(FooApplication.class);
app.setWebApplicationType(WebApplicationType.SERVLET);
app.run(args);
}
If you do not configure it , the default value will be deduced by checking if certain classes exist in the classpath.
There are 3 types of WebApplicationType will are REACTIVE , SERVLET and NONE.
And based on its value , it will choose which type of application context to be created for. See this for the logic.
REACTIVE , it will create AnnotationConfigReactiveWebServerApplicationContext SERVLET , it will create AnnotationConfigServletWebServerApplicationContextNONE, it will create AnnotationConfigApplicationContextSo it is possible that even you use certain starter , but changing the WebApplicationType value will cause different context type to be used.
We can see the output using the following code as well
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private ApplicationContext applicationContext;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
public void run(String... args) throws Exception {
System.out.println(applicationContext.getDisplayName());
}
}
I used the spring-boot-starter-web dependency , so it printed org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
On including spring-boot-starter it prints org.springframework.context.annotation.AnnotationConfigApplicationContext
So depending one the spring-boot starter dependency , spring is choosing the implementation of ApplicationContext