Enable schemaCreationSupport in spring-boot-starter-data-solr

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 06:10:36

问题


I use spring-boot-starter-data-solr and would like to make use of the schmea cration support of Spring Data Solr, as stated in the documentation:

Automatic schema population will inspect your domain types whenever the applications context is refreshed and populate new fields to your index based on the properties configuration. This requires solr to run in Schemaless Mode.

However, I am not able to achieve this. As far as I can see, the Spring Boot starter does not enable the schemaCreationSupport flag on the @EnableSolrRepositories annotation. So what I tried is the following:

@SpringBootApplication
@EnableSolrRepositories(schemaCreationSupport = true)
public class MyApplication {
  @Bean
  public SolrOperations solrTemplate(SolrClient solr) {
    return new SolrTemplate(solr);
  }
}

But looking in Wireshark I cannot see any calls to the Solr Schema API when saving new entities through the repository.

Is this intended to work, or what am I missing? I am using Solr 6.2.0 with Spring Boot 1.4.1.


回答1:


I've run into the same problem. After some debugging, I've found the root cause why the schema creation (or update) is not happening at all:

By using the @EnableSolrRepositories annotation, an Spring extension will add a factory-bean to the context that creates the SolrTemplate that is used in the repositories. This template initialises a SolrPersistentEntitySchemaCreator, which should do the creation/update.

public void afterPropertiesSet() {

  if (this.mappingContext == null) {
    this.mappingContext = new SimpleSolrMappingContext(
      new SolrPersistentEntitySchemaCreator(this.solrClientFactory)
       .enable(this.schemaCreationFeatures));
  }

  // ...
}

Problem is that the flag schemaCreationFeatures (which enables the creator) is set after the factory calls the afterPropertiesSet(), so it's impossible for the creator to do it's work.

I'll create an issue in the spring-data-solr issue tracker. Don't see any workaround right now, other either having a custom fork/build of spring-data or extend a bunch of spring-classes and trying to get the flag set before by using (but doubt of this can be done).



来源:https://stackoverflow.com/questions/39791966/enable-schemacreationsupport-in-spring-boot-starter-data-solr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!