gpt4 book ai didi

java - 简单的 Spring Boot 应用程序中使用了哪种 ApplicationContext 实现?

转载 作者:行者123 更新时间:2023-11-30 05:48:49 24 4
gpt4 key购买 nike

我学到了:

The three commonly used implementation of 'Application Context' are −

FileSystemXmlApplicationContext − This container loads the definitionsof the beans from an XML file. Here you need to provide the full pathof the XML bean configuration file to the constructor.

ClassPathXmlApplicationContext − This container loads the definitionsof the beans from an XML file. Here you do not need to provide thefull path of the XML file but you need to set CLASSPATH properlybecause this container will look bean configuration XML file inCLASSPATH.

WebXmlApplicationContext − This container loads the XML file withdefinitions 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 to DEFAULT_SERVLET_WEB_CONTEXT_CLASS for web based applications or AnnotationConfigApplicationContext for non web based applications.

其中列出了 defaults如果你不使用该方法,即。

org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext

对于基于网络的应用程序和

org.springframework.context.annotation.AnnotationConfigApplicationContext

适用于非基于网络的应用程序。

还有一个default for reactive web environments .

关于java - 简单的 Spring Boot 应用程序中使用了哪种 ApplicationContext 实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54331402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com