Class BeanHelper
java.lang.Object
de.iip_ecosphere.platform.transport.spring.BeanHelper
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TregisterInParentContext(org.springframework.context.ApplicationContext ctx, T bean) Registersbeanin the parent context ofctxwithout a qualifying name.static <T> TregisterInParentContext(org.springframework.context.ApplicationContext ctx, T bean, String beanName) Registersbeanin the parent context ofctxwith a qualifying name.
-
Constructor Details
-
BeanHelper
public BeanHelper()
-
-
Method Details
-
registerInParentContext
public static <T> T registerInParentContext(org.springframework.context.ApplicationContext ctx, T bean) Registersbeanin the parent context ofctxwithout a qualifying name.- Type Parameters:
T- the type of the bean- Parameters:
ctx- the actual application contextbean- the bean to be registered- Returns:
bean
-
registerInParentContext
public static <T> T registerInParentContext(org.springframework.context.ApplicationContext ctx, T bean, @Nullable String beanName) Registersbeanin the parent context ofctxwith a qualifying name.- Type Parameters:
T- the type of the bean- Parameters:
ctx- the actual application contextbean- the bean to be registeredbeanName- the (optional) qualifying name of the bean (may be null for none)- Returns:
bean
-