如何为spring数据solr服务器提供身份验证数据? 这是我在配置中的内容
<solr:solr-server id="solrServer" url="http://xxxxxxxx:8983/solr" />
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate" scope="singleton">
<constructor-arg ref="solrServer" />
</bean>
<bean id="searchRepository" class="com.bankofamerica.atmtech.repository.SolrJournalRepository">
<property name="solrOperations" ref="solrTemplate" />
</bean>
<bean id="App" class="App">
<property name="repo" ref="searchRepository" />
</bean>
我没有看到任何我可以设置它的属性。
答案 0 :(得分:1)
您不能直接设置Credentials
,但必须经过工厂。
@Bean
SolrTemplate solrTemplate() {
return new SolrTemplate(solrServerFactory());
}
@Bean
SolrServerFactory solrServerFactory() {
Credentials credentials = new UsernamePasswordCredentials("foo", "bar");
return new HttpSolrServerFactory(solrServer(), "collection1", credentials , "BASIC");
}
@Bean
SolrServer solrServer() {
return new HttpSolrServer("http://localhost:8983/solr");
}
我猜某种SolrAuthenticationProvider
如果在应用程序上下文中存在并应用,则在这种情况下会有意义。