有些场景下我们需要在代码中需要动态获取其它bean,这里介绍一种简单实现方式。
实现ApplicationContextAware接口
package org.ricky.spring;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* 获取spring容器,以访问容器中定义的其他bean
*/
public class SpringContextUtil implements ApplicationContextAware {
// Spring应用上下文环境
private static Applicatio

本文介绍了在Spring框架中,如何通过实现ApplicationContextAware接口动态获取其他bean的方法,详细阐述了接口的实现过程及bean的配置步骤。
773

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



