Issue
I've learned:
The three commonly used implementation of 'Application Context' are −
FileSystemXmlApplicationContext
− This container loads the definitions of the beans from an XML file. Here you need to provide the full path of the XML bean configuration file to the constructor.
ClassPathXmlApplicationContext
− This container loads the definitions of the beans from an XML file. Here you do not need to provide the full path of the XML file but you need to set CLASSPATH properly because this container will look bean configuration XML file in CLASSPATH.
WebXmlApplicationContext
− This container loads the XML file with definitions of all beans from within a web application.
So how about Spring Boot? I've read some articles, how to get ApplicationContext:
> public class A implements ApplicationContextAware {
>
> private ApplicationContext applicationContext;
>
> @Override
> public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
> this.applicationContext = applicationContext;
> }
>
> }
But which exactly implementation of Application Context is used in Spring Boot?
Solution
The entry point of a Spring Boot application is a SpringApplication
object. You can choose which implementation to use through its setApplicationContextClass(Class)
method. Its javadoc states
Sets the type of Spring
ApplicationContext
that will be created. If not specified defaults toDEFAULT_SERVLET_WEB_CONTEXT_CLASS
for web based applications orAnnotationConfigApplicationContext
for non web based applications.
which lists the defaults if you don't use that method, ie.
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
for web based applications and
org.springframework.context.annotation.AnnotationConfigApplicationContext
for non web based applications.
There's also a default for reactive web environments.
Answered By - Sotirios Delimanolis
Answer Checked By - Timothy Miller (JavaFixing Admin)