在简单的Spring Boot应用程序中使用了哪个ApplicationContext实现? [英] Which ApplicationContext implementation used in simple spring boot application?
问题描述
我了解到:
应用程序上下文"的三种常用实现是-
The three commonly used implementation of 'Application Context' are −
FileSystemXmlApplicationContext
-此容器加载定义XML文件中的Bean数量.在这里您需要提供完整的路径XML Bean配置文件传递给构造函数.
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
-此容器加载定义XML文件中的Bean数量.在这里您不需要提供XML文件的完整路径,但您需要正确设置CLASSPATH因为此容器将在其中查找bean配置XML文件CLASSPATH.
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
-此容器使用以下命令加载XML文件Web应用程序中所有bean的定义.
WebXmlApplicationContext
− This container loads the XML file with
definitions of all beans from within a web application.
那么Spring Boot呢?我读过一些文章,如何获取ApplicationContext:
So how about Spring Boot? I've read some articles, how to get ApplicationContext:
公共类A实现ApplicationContextAware {
public class A implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
但是Spring Boot中到底使用了哪种应用上下文上下文?
But which exactly implementation of Application Context is used in Spring Boot?
推荐答案
Spring Boot应用程序的入口点是 setApplicationContextClass(Class)
方法.它的javadoc状态
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
设置将要创建的Spring
ApplicationContext
的类型.如果对于Web,未指定的默认值为DEFAULT_SERVLET_WEB_CONTEXT_CLASS
非Web的基于应用程序或AnnotationConfigApplicationContext
基础的应用程序.
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
用于基于Web的应用程序和
for web based applications and
org.springframework.context.annotation.AnnotationConfigApplicationContext
用于非基于Web的应用程序.
for non web based applications.
还有一个 查看全文