java 获取spring的代理对象


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


@Component
public class ProxyUtil implements ApplicationContextAware {

private static ApplicationContext applicationContext = null;

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

}

public static <T> T getProxy(String name, Class<T> cls) {
return applicationContext.getBean(name, cls);
}

public static <T> T getProxy(Class<T> cls) {
return applicationContext.getBean(cls);
}

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM