-
Task
-
Resolution: Fixed
-
L3 - Default
-
None
-
None
Context:
We still suffer from occasional spring context initialization hiccups with
11:26:45.169 [main] WARN o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'objectMapperFactory' defined in URL [jar:file:/home/jenkins/workspace/cleanup-data-performance/m2-repository/org/camunda/optimize/optimize-backend/2.5.0-SNAPSHOT/optimize-backend-2.5.0-SNAPSHOT.jar!/org/camunda/optimize/service/util/mapper/ObjectMapperFactory.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restHighLevelClient' defined in class path resource [embeddedOptimizeContext.xml]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticSearchSchemaManager' defined in URL [jar:file:/home/jenkins/workspace/cleanup-data-performance/m2-repository/org/camunda/optimize/optimize-backend/2.5.0-SNAPSHOT/optimize-backend-2.5.0-SNAPSHOT.jar!/org/camunda/optimize/service/es/schema/ElasticSearchSchemaManager.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchMetadataService' defined in URL [jar:file:/home/jenkins/workspace/cleanup-data-performance/m2-repository/org/camunda/optimize/optimize-backend/2.5.0-SNAPSHOT/optimize-backend-2.5.0-SNAPSHOT.jar!/org/camunda/optimize/service/es/schema/ElasticsearchMetadataService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'objectMapperFactory': Requested bean is currently in creation: Is there an unresolvable circular reference?
Investigation on the cause revealed that we misuse the FactoryBean interface in the SchemaInitializingElasticsearchRestClientFactory class. We depend on other beans ,e.g. the objectMapper, however the javadoc of the FactoryBean interface states:
* <p><b>{@code FactoryBean} is a programmatic contract. Implementations are not * supposed to rely on annotation-driven injection or other reflective facilities.</b> * {@link #getObjectType()} {@link #getObject()} invocations may arrive early in * the bootstrap process, even ahead of any post-processor setup. If you need access * other beans, implement {@link BeanFactoryAware} and obtain them programmatically.
AT:
- SchemaInitializingElasticsearchRestClientFactory obtains dependencies via the beanFactory and not by injection or is initialized with a different approach (e.g. as @Bean)
- potential other affected implementations of FactoryBean are amended as well
- SchemaInitializingElasticsearchRestClientFactory is removed from spring xml config