问题描述
我使用 spring-boot-starter-data-solr 并希望利用 Spring Data Solr 的 schmea cration 支持,如 文档:
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:
每当应用程序上下文刷新时,自动模式填充将检查您的域类型,并根据属性配置将新字段填充到您的索引中.这需要 solr 以 Schemaless 模式运行.
但是,我无法做到这一点.据我所知,Spring Boot starter 没有启用 @EnableSolrRepositories 注释上的 schemaCreationSupport 标志.所以我尝试的是以下内容:
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);
}
}
但是在 Wireshark 中,当通过存储库保存新实体时,我看不到任何对 Solr Schema API 的调用.
But looking in Wireshark I cannot see any calls to the Solr Schema API when saving new entities through the repository.
这是为了工作,还是我错过了什么?我使用的是 Solr 6.2.0 和 Spring Boot 1.4.1.
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:
通过使用 @EnableSolrRepositories
注释,Spring 扩展会将工厂 bean 添加到创建存储库中使用的 SolrTemplate
的上下文中.此模板初始化一个 SolrPersistentEntitySchemaCreator
,它应该进行创建/更新.
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));
}
// ...
}
问题是标志schemaCreationFeatures
(启用创建者)是在工厂调用afterPropertiesSet()
之后设置的,所以这是不可能的让创作者完成它的工作.
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.
我将在 spring-data-solr 问题跟踪器中创建一个问题.现在看不到任何解决方法,其他要么使用自定义的分支/构建 spring-data 或扩展一堆 spring-class 并尝试通过使用之前设置标志(但对此表示怀疑).
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!