Class BeanHelper

java.lang.Object
de.iip_ecosphere.platform.transport.spring.BeanHelper

public class BeanHelper extends Object
Manual bean support functions. Usage: A binder shall provide a default instance of the transport parameters so that TransportConnector can be connected consistently. However, the binder implementations register their bean in a child application context so that the usual implementation cannot receive them via autowriting. One solution is to manually add the bean (also) to the parent application context. Thus, if your binder config values are in MyConfiguration offering a method to obtain a TransportParameter instance, then you can add the following bean registration method to your binder configuration, which uses methods of this class to also register the bean in the parent context, here with "myProto" as (optional) qualifying name.
   @Bean
   @ConditionalOnMissingBean
   public TransportParameter myTransportParameter(@Autowired ApplicationContext ctx, 
       @Autowired MyConfiguration config) {
       return TransportParameterBeanHelper.registerInParentContext(ctx, config.toTransportParameter(), "myProto");
   }
 
Author:
Holger Eichelberger, SSE
  • Constructor Details

    • BeanHelper

      public BeanHelper()
  • Method Details

    • registerInParentContext

      public static <T> T registerInParentContext(org.springframework.context.ApplicationContext ctx, T bean)
      Registers bean in the parent context of ctx without a qualifying name.
      Type Parameters:
      T - the type of the bean
      Parameters:
      ctx - the actual application context
      bean - the bean to be registered
      Returns:
      bean
    • registerInParentContext

      public static <T> T registerInParentContext(org.springframework.context.ApplicationContext ctx, T bean, @Nullable String beanName)
      Registers bean in the parent context of ctx with a qualifying name.
      Type Parameters:
      T - the type of the bean
      Parameters:
      ctx - the actual application context
      bean - the bean to be registered
      beanName - the (optional) qualifying name of the bean (may be null for none)
      Returns:
      bean