Spring mvc WebApplicationContext与ApplicationContext
在我的Spring MMVC应用程序中 我有一个xx servlet.xml对应于我的dispatcher servlet-定义我的web层bean/类,并导入另一个context.xml,它定义所有持久层bean/服务 在xx-servlet.xml中 定义了一个实现Spring mvc WebApplicationContext与ApplicationContext,spring-mvc,Spring Mvc,在我的Spring MMVC应用程序中 我有一个xx servlet.xml对应于我的dispatcher servlet-定义我的web层bean/类,并导入另一个context.xml,它定义所有持久层bean/服务 在xx-servlet.xml中 定义了一个实现ApplicationcontextAware接口的ApplicationContextProvider类 并用@Component注释了我的所有bean(表示对象),并在需要时从ApplicationContext获取这些bea
ApplicationcontextAware
接口的ApplicationContextProvider
类
并用@Component
注释了我的所有bean(表示对象),并在需要时从ApplicationContext
获取这些bean的实例(不使用WebApplicationContext
)
那么,在这种情况下,我的bean的范围是什么
另外,如果我使用WebApplicationContext
,情况会怎样
最佳实践是什么。。。使用
ApplicationContext
或WebApplicationContext
WebApplicationContext将(请求、会话、全局会话)添加到标准应用程序上下文(仅提供单例和原型作用域)。如果不指定bean范围,默认情况下它将是单例范围
最佳实践是,如果您在web环境中,您应该使用WebApplicationContext,这样您就可以使用这些额外的作用域和bean。但是如果你不使用它们,那就由你决定了
除此之外,大多数SpringMVC基础设施bean都需要WebApplicationContext