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);
        }
    }
  • 相关阅读:
    verilog编码规范
    verilog代码 想法验证---与寄存器输出有关
    MMCM与PLL
    Vivado约束文件(XDC)的探究(2)
    Vivado约束文件(XDC)的探究(1)
    VGA图像显示组成模块分析
    关于Quad PLL /CPLL参考时钟的选择
    GTX的生成(包括COMMON)
    SD-SDI播出系统---使用GTX TX产生恢复时钟
    DRP端口描述
  • 原文地址:https://www.cnblogs.com/xwjBlog/p/11647508.html
Copyright © 2011-2022 走看看