1. 创建工具类
package com.gxjf.costcontrol.core.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; /** * @author Weibn * @date 2020/6/11 */ @Component public class ApplicationContextRegister implements ApplicationContextAware { protected static ApplicationContext context; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { context = applicationContext; } public static ApplicationContext getContext() { return context; } }
2. 获取bean
ApplicationContextRegister.getContext().getBean(CimsActionConfig.class)