我学到了:
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.
那么 Spring Boot 怎么样?我读过一些文章,如何获取ApplicationContext:
> public class A implements ApplicationContextAware {
>
> private ApplicationContext applicationContext;
>
> @Override
> public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
> this.applicationContext = applicationContext;
> }
>
> }
但是 Spring Boot 中到底使用了哪种应用程序上下文实现?
最佳答案
Spring Boot 应用程序的入口点是 SpringApplication
目的。您可以通过其 setApplicationContextClass(Class)
选择要使用的实现。方法。它的 javadoc 指出
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.
其中列出了 defaults如果你不使用该方法,即。
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
对于基于网络的应用程序和
org.springframework.context.annotation.AnnotationConfigApplicationContext
适用于非基于网络的应用程序。
关于java - 简单的 Spring Boot 应用程序中使用了哪种 ApplicationContext 实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54331402/