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

com.cifaz.tools.util.SpringContextUtil Maven / Gradle / Ivy

The newest version!
package com.cifaz.tools.util;

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

@Component
public class SpringContextUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static  T getBean(String name) throws BeansException {
        return (T) applicationContext.getBean(name);
    }

    public static  T getBean(Class requiredType) throws BeansException {
        return applicationContext.getBean(requiredType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy