Class ApplicationContextProvider
java.lang.Object
io.github.xezzon.zeroweb.common.context.ApplicationContextProvider
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
@Component
public class ApplicationContextProvider
extends Object
implements org.springframework.context.ApplicationContextAware
提供对 Spring 应用上下文的静态访问。
该类通过实现
ApplicationContextAware 接口,在 Spring 容器初始化时自动设置应用上下文。
允许应用程序中非 Spring 管理的组件获取 Spring Bean。-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.context.ApplicationContextget()获取 Spring 应用上下文。voidsetApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) 实现ApplicationContextAware接口,由 Spring 容器自动调用。
-
Constructor Details
-
ApplicationContextProvider
public ApplicationContextProvider()
-
-
Method Details
-
get
public static org.springframework.context.ApplicationContext get()获取 Spring 应用上下文。
该方法允许任何组件在应用程序中获取已初始化的 Spring 应用上下文, 从而访问由 Spring 管理的 Bean。
- Returns:
- 当前的 Spring 应用上下文。
-
setApplicationContext
public void setApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) 实现
ApplicationContextAware接口,由 Spring 容器自动调用。当应用上下文可用时,Spring 会自动将其实例注入到此方法中。 该方法将传入的上下文设置到静态变量中,供其他部分使用。
- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Parameters:
applicationContext- 由 Spring 注入的应用上下文实例。
-