Java tutorial
/** * Program : SpringContextUtil.java * Author : ruanan * Create : 20151024 ?12:57:52 * * Copyright 2015 ruanan. All rights reserved. * * This software is the confidential and proprietary information * of ruanan. * You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement * you entered into with ruanan. * */ package com.kun.common.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; /** * spring * * @version 1.0.0 * @date 20151024 ?12:57:52 */ public class SpringContextUtil implements ApplicationContextAware { private static ApplicationContext applicationContext; // Spring /** * ApplicationContextAware? * * @param applicationContext * @throws BeansException */ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { SpringContextUtil.applicationContext = applicationContext; } /** * @return ApplicationContext */ public static ApplicationContext getApplicationContext() { return applicationContext; } /** * ? * * @param name * @return Object ??bean * @throws BeansException */ public static Object getBean(String name) throws BeansException { return applicationContext.getBean(name); } /** * BeanFactory????beantrue * * @param name * @return boolean */ public static boolean containsBean(String name) { return applicationContext.containsBean(name); } }