类 SpringBeanService

java.lang.Object
com.luna.common.spring.SpringBeanService
所有已实现的接口:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Component public class SpringBeanService extends Object implements org.springframework.context.ApplicationContextAware
Spring的bean加载服务类
  • 字段详细资料

    • applicationContext

      protected static org.springframework.context.ApplicationContext applicationContext
      spring bean上下文
  • 构造器详细资料

    • SpringBeanService

      public SpringBeanService()
  • 方法详细资料

    • getBeanByName

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

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

      public static <T> Map<String,T> getBeansOfType(Class<T> clazz)
      获取此类型所有的bean
      参数:
      clazz -
      返回:
      抛出:
      org.springframework.beans.BeansException
    • getSingleBeanByType

      public static <T> T getSingleBeanByType(Class<T> clazz) throws Exception
      根据class 类型获取bean
      参数:
      clazz -
      返回:
      抛出:
      org.springframework.beans.BeansException - 当有继承或者接口时(多个实现类)getBean(clazz)会报错 所以通过class name比较来获取唯一那个bean
      Exception
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      指定者:
      setApplicationContext 在接口中 org.springframework.context.ApplicationContextAware
      抛出:
      org.springframework.beans.BeansException