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

com.biz.common.bean.BizXBeanUtils Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
package com.biz.common.bean;

import com.biz.common.application.aware.ApplicationContextAwareUtils;
import org.springframework.context.ApplicationContext;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Bean Util
 * 对Bean的一些操作
 *
 * @author francis
 * @create: 2023-04-09 22:16
 **/
public final class BizXBeanUtils {

    /**
     * 获取 Bean
     *
     * @param clazz
     * @param 
     * @return
     */
    public static  T getBean(Class clazz) {
        return getApplicationContext().getBean(clazz);
    }

    /**
     * 获取存在 X 注解的 Bean
     *
     * @param clazz X 注解
     * @return
     */
    public static Map getBeansWithAnnotation(Class clazz) {
        return getApplicationContext().getBeansWithAnnotation(clazz);
    }

    /**
     * 获取所有的 Bean Class
     *
     * @return
     */
    public static List> getBeanDefinitionClasses() {
        List> classList = new ArrayList<>();
        for (String beanName : getApplicationContext().getBeanDefinitionNames()) {
            classList.add(getApplicationContext().getBean(beanName).getClass());
        }
        return classList;
    }

    /**
     * 获取所有的 Bean
     *
     * @return 所有的 Bean
     */
    public static String[] getBeanDefinitionNames() {
        return getApplicationContext().getBeanDefinitionNames();
    }


    /**
     * 获取 ApplicationContext
     *
     * @return ApplicationContext
     */
    private static ApplicationContext getApplicationContext() {
        return ApplicationContextAwareUtils.getApplicationContext();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy