如何拿到本类的动态对象

@Component
public class ProxyUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ProxyUtil.applicationContext = applicationContext;

    }

    /**
     * 根据class拿到bean的代理对象
     * @param cls
     * @param <T>
     * @return
     */
        public static <T> T getProxy(Class<T> cls) {
            return applicationContext.getBean(cls);
        }

}

 

posted @ 2022-09-06 16:52  cire  阅读(22)  评论(0)    收藏  举报
/* 看板娘 */