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

com.github.yt.mybatis.utils.SpringContextUtils Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package com.github.yt.mybatis.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.AbstractRefreshableWebApplicationContext;

import java.util.Map;

@Component
public class SpringContextUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public SpringContextUtils() {
    }

    public void setApplicationContext(ApplicationContext _applicationContext) {
        applicationContext = _applicationContext;
    }

    public static void refresh() {
        ((AbstractRefreshableWebApplicationContext) applicationContext).refresh();
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static  Map getBeans(Class type) {
        return applicationContext.getBeansOfType(type);
    }

    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }


    public static  T getBean(Class beanClass) {
        return applicationContext.getBean(beanClass);
    }

    public static Boolean containsBean(String beanName) {
        return applicationContext.containsBean(beanName);
    }

    public static String getProperty(String key) {
        return PropertyConfigurer.getProperty(key);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy