spring boot servlet context与应用程序上下文

问题描述 投票:0回答:1

我来自Spring MVC多年,我试图了解一些与Spring启动的关键差异。

使用Spring MVC,我曾经在应用程序上下文和servlet上下文之间做了非常明确的区分。

使用Spring启动时,看起来servlet上下文已经被弃用,并且通过autoconfig机制创建的所有bean都存在于应用程序上下文中。

你仍然可以创建你的servlet上下文,你必须记住autoconfig正在使用应用程序上下文。

例如,一个含义是@RestControllers和@Controllers存在于应用程序上下文中,Spring Boot autoconfig servlet调度程序将在应用程序上下文中使用任何@RestController@Controller带注释的bean。

你能帮我确认一下还是让我明白我在这里缺少什么?

spring spring-boot
1个回答
1
投票

在spring-springMVC系统中,您提到了两个容器。对于springboot-springMVC,通过实现ApplicationContextAware在控制器和服务中进行调试

context in service

context in controller

他们使用相同的全局applicationContext

org.springframework.boot.web.servlet.contextAnnotationConfigServletWebServerApplicationContext
© www.soinside.com 2019 - 2024. All rights reserved.