Class SpringUtil


  • public final class SpringUtil
    extends Object
    Since:
    2018.2
    Author:
    Maxim.Zaytsev
    • Constructor Summary

      Constructors 
      Constructor Description
      SpringUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T getOwnBean​(org.springframework.context.ApplicationContext context, Class<T> type)
      Returns instance of specified type from specified context but ignore beans of parent context.
      static <T> T getOwnBean​(org.springframework.context.ApplicationContext context, Class<T> type, T defaultBean)
      Returns instance of specified type from specified context but ignore beans of parent context.
      static <T> List<T> getOwnBeans​(org.springframework.context.ApplicationContext context, Class<T> type)
      Returns all instances of specified type from specified context but ignore beans of parent context
    • Constructor Detail

      • SpringUtil

        public SpringUtil()
    • Method Detail

      • getOwnBeans

        @NotNull
        public static <T> List<T> getOwnBeans​(@NotNull
                                              org.springframework.context.ApplicationContext context,
                                              @NotNull
                                              Class<T> type)
        Returns all instances of specified type from specified context but ignore beans of parent context
        Parameters:
        context - specified context
        type - type the bean must match
        Returns:
        list of fount beans
      • getOwnBean

        @Nullable
        public static <T> T getOwnBean​(@NotNull
                                       org.springframework.context.ApplicationContext context,
                                       @NotNull
                                       Class<T> type)
        Returns instance of specified type from specified context but ignore beans of parent context.
        Parameters:
        context - specified context
        type - type the bean must match
        Returns:
        found instance or null if context doesn't contain bean or contains many beans of specified type
      • getOwnBean

        @NotNull
        public static <T> T getOwnBean​(@NotNull
                                       org.springframework.context.ApplicationContext context,
                                       @NotNull
                                       Class<T> type,
                                       T defaultBean)
        Returns instance of specified type from specified context but ignore beans of parent context.
        Parameters:
        context - specified context
        type - type the bean must match
        defaultBean - default instance which must be returned if context doesn't contain bean or contains many beans of specified type
        Returns:
        found instance or defaultBean if context doesn't contain bean or contains many beans of specified type