/****************************************************************************** * Copyright (C) 2015 Shenzhen Penguin Network Technology Co., Ltd * All Rights Reserved. * ±¾Èí¼þΪÉîÛÚÆó¶ìÍøÂç¿Æ¼¼ÓÐÏÞ¹«Ë¾¿ª·¢ÑÐÖÆ¡£Î´¾­±¾¹«Ë¾ÕýʽÊéÃæÍ¬Ò⣬ÆäËûÈκθöÈË¡¢ÍÅÌå * ²»µÃʹÓᢸ´ÖÆ¡¢Ð޸Ļò·¢²¼±¾Èí¼þ. *****************************************************************************/ package com.qxueyou.scc.base.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; /** * * Spring ¹¤¾ßÀà,Ìṩ»ñÈ¡SpingÉÏÏÂÎÄ»·¾³¼°»ñÈ¡BeanµÄ½Ó¿Ú * @history 2010-09-12 Ïĵ»¢ н¨ * */ @Component public class SpringUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; private SpringUtil(){} /** * »ñÈ¡bean * @param ·ºÐÍÀàÐÍ * @param name bean name * @param clz bean ÀàÐÍ * @param context servletÉÏÏÂÎÄ * @return beanʵÀý */ public static T getBean(String name,Class clz){ return applicationContext.getBean(name,clz); } /** * »ñÈ¡bean * @param ·ºÐÍÀàÐÍ * @param clz bean ÀàÐÍ * @param context servletÉÏÏÂÎÄ * @return beanʵÀý */ public static T getBean(Class clz){ return applicationContext.getBean(clz); } @SuppressWarnings("unchecked") public static T getBean(String name) throws BeansException { return (T) applicationContext.getBean(name); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { SpringUtil.applicationContext= applicationContext; } }