zoukankan      html  css  js  c++  java
  • 不需要spring管理,自己根据名字取到对应的bean

    package com.yiban.abc.util;
    
    import org.springframework.beans.BeansException;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.BeanFactoryAware;
    import org.springframework.beans.factory.support.DefaultListableBeanFactory;
    import org.springframework.context.annotation.Configuration;
    
    import java.util.Map;
    
    
    @Configuration
    public class SpringBeanUtil implements BeanFactoryAware {
        private static BeanFactory beanFactory;
        private static DefaultListableBeanFactory listtableBeanFactory;
    
        public SpringBeanUtil() {
        }
    
        public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
            SpringBeanUtil.beanFactory = beanFactory;
            listtableBeanFactory = (DefaultListableBeanFactory)beanFactory;
        }
    
        public static Object getBean(String name) throws BeansException {
            return beanFactory.getBean(name);
        }
    
        public static <T> T getBean(Class<T> requiredType) throws BeansException {
            return beanFactory.getBean(requiredType);
        }
    
        public static <T> T getBean(String name, Class<T> requiredType) throws BeansException {
            return beanFactory.getBean(name, requiredType);
        }
    
        public static <T> Map<String, T> getBeansOfType(Class<T> requiredType) throws BeansException {
            return listtableBeanFactory.getBeansOfType(requiredType);
        }
    }
  • 相关阅读:
    Pandas | 21 日期功能
    Pandas | 20 级联
    Pandas | 19 合并/连接
    Pandas | GroupBy 分组
    Pandas | 缺失数据处理
    Pandas | 16 聚合
    Pandas | 15 窗口函数
    Pandas | 14 统计函数
    Pandas | 13 索引和选择数据
    Pandas | 12 选项和自定义
  • 原文地址:https://www.cnblogs.com/xwjBlog/p/11647508.html
Copyright © 2011-2022 走看看