Class SpringUtils

java.lang.Object
cn.mapway.spring.tools.SpringUtils
All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor

@Component public final class SpringUtils extends Object implements org.springframework.beans.factory.config.BeanFactoryPostProcessor
spring工具类 方便在非spring管理环境中获取bean
Author:
cangling
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
    static String[]
    如果给定的bean名字在bean定义中有别名,则返回这些别名
    static <T> T
    getAopProxy(T invoker)
    获取aop代理对象
    static <T> T
    getBean(Class<T> clz)
    获取类型为requiredType的对象
    static <T> T
    获取对象
    static Class<?>
     
    static boolean
    判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
    void
    postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringUtils

      public SpringUtils()
  • Method Details

    • postProcessBeanFactory

      public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
      Throws:
      org.springframework.beans.BeansException
    • getBean

      public static <T> T getBean(String name) throws org.springframework.beans.BeansException
      获取对象
      Parameters:
      name -
      Returns:
      Object 一个以所给名字注册的bean的实例
      Throws:
      org.springframework.beans.BeansException
    • getBean

      public static <T> T getBean(Class<T> clz) throws org.springframework.beans.BeansException
      获取类型为requiredType的对象
      Parameters:
      clz -
      Returns:
      Throws:
      org.springframework.beans.BeansException
    • containsBean

      public static boolean containsBean(String name)
      如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true
      Parameters:
      name -
      Returns:
      boolean
    • isSingleton

      public static boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到,将会抛出一个异常(NoSuchBeanDefinitionException)
      Parameters:
      name -
      Returns:
      boolean
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getType

      public static Class<?> getType(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Parameters:
      name -
      Returns:
      Class 注册对象的类型
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getAliases

      public static String[] getAliases(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      如果给定的bean名字在bean定义中有别名,则返回这些别名
      Parameters:
      name -
      Returns:
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getAopProxy

      public static <T> T getAopProxy(T invoker)
      获取aop代理对象
      Parameters:
      invoker -
      Returns: