All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.cwdtom.hermes.entity.ApplicationContextHelper Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package com.github.cwdtom.hermes.entity;

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

/**
 * 帮助获取spring上下文
 *
 * @author chenweidong
 * @since 2.0.1
 */
public class ApplicationContextHelper implements ApplicationContextAware {
    /**
     * spring上下文
     */
    private static ApplicationContext applicationContext;

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

    /**
     * 获取bean
     *
     * @param name bean name
     * @param clz  bean type
     * @param   bean type
     * @return bean
     */
    public static  T getBean(String name, Class clz) {
        return ApplicationContextHelper.applicationContext.getBean(name, clz);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy