package com.bis.majian.practice.module.spring.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class SpringContextHelper implements ApplicationContextAware {
private static ApplicationContext context = null;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
context = applicationContext;
}
public static Object getBean(String name){
return context.getBean(name);
}
} 通过实现ApplicationContextAware对象注入Spring上下文
最新推荐文章于 2025-07-04 10:41:42 发布
本文介绍了一个名为SpringContextHelper的实用工具类,该类实现了ApplicationContextAware接口,并提供了一个静态方法getBean,用于从Spring应用上下文中获取指定名称的Bean实例。
3618

被折叠的 条评论
为什么被折叠?



