zoukankan      html  css  js  c++  java
  • spring上下文快速获取方法

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

    /**
    * spring 工具栏
    *
    * @author renj
    *
    */
    public class ApplicationContextHelper implements ApplicationContextAware {
    private static ApplicationContext appCtx;

    /**
    * 此方法可以把ApplicationContext对象inject到当前类中作为一个静态成员变量。
    *
    * @param applicationContext
    * ApplicationContext 对象.
    * @throws BeansException
    * @author wangdf
    */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
    throws BeansException {
    appCtx = applicationContext;
    }

    /**
    * 获取ApplicationContext
    *
    * @return
    * @author wangdf
    */
    public static ApplicationContext getApplicationContext() {
    return appCtx;
    }

    /**
    * 这是一个便利的方法,帮助我们快速得到一个BEAN
    *
    * @param beanName
    * bean的名字
    * @return 返回一个bean对象
    * @author wangdf
    */
    public static Object getBean(String beanName) {
    return appCtx.getBean(beanName);
    }
    }

  • 相关阅读:
    POJ:2431-Expedition
    poj:3253-Fence Repair
    POJ:3617-Best Cow Line(贪心)
    IOS各种传值方式
    imageDownloader
    Android放大镜的实现
    Delphi 串口通信(1)
    UVA 10131
    Skew Join与Left Semi Join相关
    Android动画 fillAfter和fillBefore
  • 原文地址:https://www.cnblogs.com/UUUz/p/9373603.html
Copyright © 2011-2022 走看看