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

org.babyfish.jimmer.spring.util.ApplicationContextUtils Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.spring.util;

import org.springframework.context.ApplicationContext;

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

/**
 * {@link org.springframework.context.ApplicationContext#getBeansOfType(Class)}
 * hides exceptions such as dependency cycle. Use this class to replace it.
 */
public class ApplicationContextUtils {

    @SuppressWarnings("unchecked")
    public static  List getBeansOfType(ApplicationContext ctx, Class type) {
        String[] beanNames = ctx.getBeanNamesForType(type);
        if (beanNames.length == 0) {
            return Collections.emptyList();
        }
        List beans = new ArrayList<>(beanNames.length);
        for (String beanName : beanNames) {
            Object bean = ctx.getBean(beanName);
            if (!bean.getClass().getName().equals("org.springframework.beans.factory.support.NullBean")) {
                beans.add((T)bean);
            }
        }
        return beans;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy