Class SpringBeanService

java.lang.Object
com.luna.common.spring.SpringBeanService
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Component public class SpringBeanService extends Object implements org.springframework.context.ApplicationContextAware
Spring的bean加载服务类
  • Field Details

    • applicationContext

      protected static org.springframework.context.ApplicationContext applicationContext
      spring bean上下文
  • Constructor Details

    • SpringBeanService

      public SpringBeanService()
  • Method Details

    • getBeanByName

      public static <T> T getBeanByName(String name, Class<T> clazz) throws org.springframework.beans.BeansException
      获取bean实例
      Throws:
      org.springframework.beans.BeansException
    • getBeanByName

      public static Object getBeanByName(String name) throws org.springframework.beans.BeansException
      获取bean实例
      Throws:
      org.springframework.beans.BeansException
    • getBeansOfType

      public static <T> Map<String,T> getBeansOfType(Class<T> clazz)
      获取此类型所有的bean
      Parameters:
      clazz -
      Returns:
      Throws:
      org.springframework.beans.BeansException
    • getSingleBeanByType

      public static <T> T getSingleBeanByType(Class<T> clazz) throws Exception
      根据class 类型获取bean
      Parameters:
      clazz -
      Returns:
      Throws:
      org.springframework.beans.BeansException - 当有继承或者接口时(多个实现类)getBean(clazz)会报错 所以通过class name比较来获取唯一那个bean
      Exception
    • 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