Class SpringUtils

java.lang.Object
com.codeupsoft.base.service.utils.SpringUtils
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

public class SpringUtils extends Object implements org.springframework.context.ApplicationContextAware
Spring工具类,用于获取和注册Bean.
Author:
Liu,Dongdong
  • Constructor Details

    • SpringUtils

      public SpringUtils()
  • Method Details

    • getBean

      public static <T> T getBean(String name)
      根据Bean名称获取Bean实例.
      Parameters:
      name - Bean名称
      Returns:
      Bean实例
    • getBean

      public static <T> T getBean(Class<T> clazz)
      根据Bean类型获取Bean实例.
      Parameters:
      clazz - Bean类型
      Returns:
      Bean实例
    • getBean

      public static <T> T getBean(String name, Class<T> clazz)
      根据Bean名称和类型获取Bean实例.
      Parameters:
      name - Bean名称
      clazz - Bean类型
      Returns:
      Bean实例
    • containsBean

      public static boolean containsBean(String name)
      判断是否包含指定名称的Bean.
      Parameters:
      name - Bean名称
      Returns:
      是否包含
    • isSingleton

      public static boolean isSingleton(String name)
      判断指定名称的Bean是否为单例.
      Parameters:
      name - Bean名称
      Returns:
      是否为单例
    • registerBean

      public static void registerBean(String beanName, Object beanInstance)
      动态注册Bean到Spring容器中.
      Parameters:
      beanName - Bean的名称
      beanInstance - Bean的实例
    • removeBean

      public static void removeBean(String beanName)
      从Spring容器中移除指定名称的Bean.
      Parameters:
      beanName - Bean的名称
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException