package com.doumee.core.utils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; /** * Spring上下文工具 * @author Eva.Caesar Liu * @since 2025/03/31 16:44 */ @Component public class ApplicationContextHelper { @Autowired public ApplicationContext applicationContext; /** * 获取Bean实例 * * @param name 类注册名称 * @return Object */ public Object getBean(String name) { return applicationContext.getBean(name); } /** * 获取Bean实例 * * @param clazz Class * @return T */ public T getBean(Class clazz){ return applicationContext.getBean(clazz); } /** * 获取Bean实例 * * @param name 类注册名称 * @param clazz Class * @return T */ public T getBean(String name, Class clazz) { return applicationContext.getBean(name, clazz); } }