Skip to content

Spring Data Couchbase Auto Configuration prevents automatic index creation from occurring #24525

Closed
@aaronjwhiteside

Description

@aaronjwhiteside

Auto index creation support appears broken because the CouchbaseMappingContext @Bean is initialized before the CouchbaseTemplate has had a chance to register the CouchbasePersistentEntityIndexCreator as an ApplicationListener.

Bean dependencies:

  • org.springframework.boot.autoconfigure.data.couchbase.CouchbaseClientFactoryDependentConfiguration#couchbaseTemplate requires MappingCouchbaseConverter
  • org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataConfiguration#couchbaseMappingConverter requires CouchbaseMappingContext
  • org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataConfiguration#couchbaseMappingContext

How the beans are initialized:

CouchbaseMappingContext implements InitializingBean which calls CouchbaseMappingContext#initalize to then iterate over the supplied (from factory method) initialEntitySet and calls CouchbaseMappingContext#addPersistentEntity on each one, which ends up publishing a MappingContextEvent for each entity found.

CouchbaseTemplate creates a CouchbasePersistentEntityIndexCreator in its constructor, CouchbaseTemplate also implements ApplicationContextAware and when setApplicationContext() is called ends up adding the CouchbasePersistentEntityIndexCreator instance to the ApplicationContext as a ApplicationListener.

CouchbasePersistentEntityIndexCreator implements ApplicationListener and listens for MappingContextEvent's, and handles the automatic index creation logic.

Possible solution:

I think ideally the correct solution will involve moving the CouchbasePersistentEntityIndexCreator instance creation OUT of the CouchbaseTemplate and into an appropriate @Configuration class.

But I have a feeling that marking the CouchbaseMappingContext @Bean as @Lazy might be the more practical solution? I haven't tested this theory so..

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions