在spring-boot-starter-data-solr中启用schemaCreationSupport [英] Enable schemaCreationSupport in spring-boot-starter-data-solr

查看:83
本文介绍了在spring-boot-starter-data-solr中启用schemaCreationSupport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用spring-boot-starter-data-solr,并想利用Spring Data Solr的schmea cration支持,如解决方案

我遇到了同样的问题.经过一些调试后,我找到了根本不进行模式创建(或更新)的根本原因:

通过使用@EnableSolrRepositories批注,Spring扩展将在工厂上下文中添加一个工厂bean,以创建在存储库中使用的SolrTemplate.此模板会初始化SolrPersistentEntitySchemaCreator应进行创建/更新.

public void afterPropertiesSet() {

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

  // ...
}

问题是在工厂调用后设置了标记schemaCreationFeatures(启用创建者),因此创建者无法完成工作.

我将在spring-data-solr问题跟踪器中创建一个问题.现在看不到任何解决方法,其他方法是具有自定义的fork/build的spring-data或扩展一堆spring-classs并尝试通过使用来获取标志集(但可以做到这一点)./p>

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.

解决方案

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).

这篇关于在spring-boot-starter-data-solr中启用schemaCreationSupport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆