【问题标题】:No Association Found Error while indexing data to Solr using Spring-Data-Solr使用 Spring-Data-Solr 将数据索引到 Solr 时未发现关联错误
【发布时间】:2018-11-26 07:20:39
【问题描述】:

我正在尝试一个 spring data mongoDB + spring data solr 的示例服务应用程序,其中 MongoDB 用于持久化数据和 solr 用于索引和搜索。

对 MongoDB 的保存操作在服务类中成功发生。但是在调用 SolrOperation save() 方法时,服务会崩溃,错误日志如下:

SEVERE [com.sun.jersey.spi.container.ContainerResponse] (defaulttask-1)The 
RuntimeException could not be mapped to a response, re-throwing the HTTP 
container:org.springframework.data.solr.UncategorizedSolrException:No
association fond!; nested exception is java.lang.IllegalStateException: No 
association found! at     org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:171)

当我进一步深入分析日志时,它说:

Caused by: java.lang.IllegalStateException:No association found!
at org.springframework.data.mapping.PersistentProperty.getRequiredAssociation(PersistentProperty.java:166)

convertBeanToSolrInputDocument ()convertBeanToSolrInputDocument () 内的行 getConverter().write(bean, document) SolrTemplate 正在引发错误。

DAO 方法

public String addToRepo(MyEntity myEntity){
mongoOperation.save(myEntity); //works fine data saved to MongoDB
solrOperation.save("collectionName",myEntity); //generates above exception
return "success";
}

我正在使用 Spring 5 + solrj-6.1.0 + spring-data-solr-4.0.2。

solroperation 已正确加载为:

ApplicationContext SOLR_CONFIG_APP_CTX = new AnnotationConfigApplicationContext(SpringSolrConfig.class);
SolrOperations solrOperation = (SolrOperations)ctx.getBean("solrTemplate");

public static final SolrOperations SOLR_OPS=
(SolrOperations)SOLR_CONFIG_APP_CTX.getBean("solrTemplate");

SpringSolrConfig.java

@Configuration
public class SpringSolrConfig extends AbstractSolrConfig {
public SolrClientFactory solrClientFactory (){
SolrClient solrClient = new HttpSolrClient.Builder(solrUrl).build();
HttpSolrClientFactory solrClientFactory = new HttpSolrClientFactory (solrClient);
return solrClientFactory;
}
}

SpringConfig.xml 文件如下所示:

<mongo:mongo host="195.168.1.140" port="27017"/>
<mongo:dbfactory dbname="myDB"/>
<bean id="mongoTemplate"
class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg-name="mongoDbFactory" ref="mongoDbFactory"/>
</bean>
<repositories base-package="sample.package.repositories"/>
<bean id="myEntityRepo" class="sample.package..repositories.MyEntityRepositoryInterface"/>
<solr:repositories base-package="sample.package.repositories"/>
<solr:sorl-server id="solrServer" url="http://localhost:8983/solr"/>
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg index="0" ref="solrServer"/>
</bean>

提前感谢您帮助我解决此问题!

【问题讨论】:

  • 你有运行 sn-p 来重现错误吗?
  • 我的工作站和互联网因安全原因断开连接。我很快就会给你一个sn-p。同时,我关注了您jira.spring.io/browse/DATASOLR-394 发布的其他一些帖子/解决方案,并更新了我的 SpringConfig 文件以使用 SolrJConverter 覆盖 MappingSolrCnoverter。这帮助我消除了之前的错误。但现在它发布了一个不同的错误“java.lang.NoClassDefFoundError: org/noggit/CharArr at”。我正在解决这个问题。非常感谢您的回复,克里斯托夫!

标签: solr spring-data-solr


【解决方案1】:

我如下更新了我的 SpringSolrConfig 文件来解决问题。礼貌:https://jira.spring.io/browse/DATASOLR-394

    @Configuration
    public class SpringSolrConfig extends AbstractSolrConfig {

    String solrUrl = "http://localhost:8983/solr/"; // TODO read this ideally from spring-configuration.xml file
    public SolrClientFactory solrClientFactory (){
    SolrClient solrClient = new HttpSolrClient.Builder(solrUrl).build();
    HttpSolrClientFactory solrClientFactory = new HttpSolrClientFactory (solrClient);
    return solrClientFactory;
    }

    @Bean
    public SolrTemplate solrTemplate () {
    SolrTemplate solrTemplateObj = new SolrTemplate(solrClientFactory));
    // This ensures that the default MappingSolrConverter.java is not used for converting the bean to a Solr Document before indexing
    solrTemplateObj.setSolrConverter(new SolrJConverter());
    return solrTemplateObj;
    }

    }

【讨论】:

    猜你喜欢
    • 2015-04-05
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 2019-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多