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

be.bagofwords.util.SpringUtils Maven / Gradle / Ivy

package be.bagofwords.util;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class SpringUtils {

    public static  List getInstantiatedBeans(ApplicationContext applicationContext, Class _class) {
        List singletons = new ArrayList<>();
        String[] all = applicationContext.getBeanNamesForType(_class,false, false);
        ConfigurableListableBeanFactory clbf = ((AbstractApplicationContext) applicationContext).getBeanFactory();
        for (String name : all) {
            Object s = clbf.getSingleton(name);
            if (s != null && _class.isAssignableFrom(s.getClass())) {
                ((List) singletons).add(s);
            }
        }
        return singletons;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy