在spring-boot-start -data-solr中启用schemaCreationSupport



我使用Spring -boot-start - Data - Solr,并希望使用Spring Data Solr的模式创建支持,如文档中所述:

自动模式填充将在刷新应用程序上下文时检查域类型,并根据属性配置向索引填充新字段。这需要solr在Schemaless模式下运行。

然而,我不能做到这一点。据我所知,Spring Boot启动器没有在@EnableSolrRepositories注释上启用schemaCreationSupport标志。所以我尝试的是:

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

但是在Wireshark中,当通过存储库保存新实体时,我看不到对Solr Schema API的任何调用。

这是打算工作,还是我错过了什么?我使用的是Solr 6.2.0和Spring Boot 1.4.1.

我也遇到过同样的问题。经过一些调试,我找到了模式创建(或更新)根本没有发生的根本原因:

通过使用@EnableSolrRepositories注释,Spring扩展将向创建存储库中使用的SolrTemplate的上下文中添加一个工厂bean。这个模板初始化了一个SolrPersistentEntitySchemaCreator,其中应该做创建/更新

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

问题是标志schemaCreationFeatures(启用创建者)在工厂调用 afterPropertiesSet()之后被设置为,因此创建者不可能完成它的工作。

我将在spring-data-solr问题跟踪器中创建一个问题。现在没有看到任何解决方案,除了有一个自定义的fork/构建spring-data或扩展一堆spring-class并试图通过使用(但怀疑这可以做到)获得之前设置的标志。

最新更新