我是SOLR的新手,但我已经安装了SOLR,并设置了一个核心"participant_dev“。我们有多个环境,即.、CI、Dev、QA、UAT和Prod。
对于单个核,配置非常简单。在Spring应用程序中,添加solr服务器url,如下所示
spring:
data:
solr:
host: server urlsolr文档注释为
@SolrDocument(solrCoreName = "participant_dev")
public class Solr Participant{
....
}这是可行的,但现在的要求是,当应用程序移动到不同的环境中时,我必须设置solr内核,如‘参与者_ci’、‘参与者_qa’、'participant_uat‘等等。您能否建议如何根据环境更改solr核心名称。所以在CI中,
@SolrDocument(solrCoreName = "participant_ci")
public class Solr Participant{
....
}
In QA,
@SolrDocument(solrCoreName = "participant_qa")
public class Solr Participant{
....
}发布于 2016-05-30 16:32:01
您可以通过在Application类中创建solr客户端bean并删除@SolrDocument注释来进行设置。因此,默认集合将按指定的方式进行。
@Bean
public SolrClient solrClient()
{
CloudSolrClient client = new CloudSolrClient(env.getRequiredProperty("spring.data.solr.zk-host"));
client.setDefaultCollection("participant_"+env.getActiveProfiles()[0]);
return client;
}另一种选择是创建自定义存储库,但这会增加许多不必要的代码。
https://stackoverflow.com/questions/37484909
复制相似问题