[
https://issues.apache.org/jira/browse/CAMEL-21034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17871002#comment-17871002
]
Claude Mamo commented on CAMEL-21034:
-------------------------------------
The problem is that the context's injector isn't changed later to
{_}SpringInjector{_}, as I would expect, so beans registered in Spring are not
injected into beans defined in Camel which means that @Autowired references
remain null. I got around this by registering the following
{_}BeanPostProcessor{_}:
{code:java}
public class CamelContextBeanPostProcessor implements BeanPostProcessor {
private final ConfigurableApplicationContext applicationContext;
public CamelContextBeanPostProcessor(ConfigurableApplicationContext
applicationContext) {
this.applicationContext = applicationContext;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof CamelContext) {
((CamelContext) bean).setInjector(new
SpringInjector(applicationContext));
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
}
{code}
> DefaultInjector created instead of SpringInjector when using custom
> ModelReifierFactory in Spring Boot app
> ----------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-21034
> URL: https://issues.apache.org/jira/browse/CAMEL-21034
> Project: Camel
> Issue Type: Bug
> Components: came-core, camel-spring-boot
> Affects Versions: 4.6.0
> Environment: Spring Boot
> Reporter: Claude Mamo
> Priority: Minor
> Attachments: call-stack.txt
>
>
> I'm referencing a custom model reifier factory in
> _META-INF/services/org/apache/camel/model-reifier-factory_ which is causing
> DefaultInjector to be used instead of the expected SpringInjector.
> SpringCamelContext creates the injector when loading a custom
> ModelReifierFactory. SpringInjector requires the application context, but
> since the application context hasn't yet been set on SpringCamelContext, the
> SpringInjector cannot be created so SpringCamelContext falls back to
> DefaultInjector. I've attached the call stack of this behaviour.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)