Java 如何在Spring Data Solr中关闭SolrTemplate
我已经使用CommandLineRunner接口编写了一个Spring引导控制台应用程序(版本2.2.4.Spring数据解决方案版本4.1.4)。我已经连接了一个启动SolrTemplate连接的服务。我使用它对Solr索引运行一些查询,然后想关闭应用程序 当我调试应用程序时,我可以逐步遍历整个应用程序,但当应用程序离开main()时,它将挂起。我假设SolrTemplate正在等待另一个查询。有办法关闭SolrTemplate吗Java 如何在Spring Data Solr中关闭SolrTemplate,java,solr,solrj,spring-data-solr,Java,Solr,Solrj,Spring Data Solr,我已经使用CommandLineRunner接口编写了一个Spring引导控制台应用程序(版本2.2.4.Spring数据解决方案版本4.1.4)。我已经连接了一个启动SolrTemplate连接的服务。我使用它对Solr索引运行一些查询,然后想关闭应用程序 当我调试应用程序时,我可以逐步遍历整个应用程序,但当应用程序离开main()时,它将挂起。我假设SolrTemplate正在等待另一个查询。有办法关闭SolrTemplate吗 @Configuration @EnableSolrRepos
@Configuration
@EnableSolrRepositories(basePackages = { "org.ihc.hdd.serviceExample.facet.repository" })
public class SolrConfig {
@Value("${spring.data.solr.zk-host}")
private String zkHost;
@Bean
public SolrTemplate solrTemplate() throws Exception {
String[] zkHosts = this.zkHost.split(",");
CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder(Arrays.asList(zkHosts), Optional.empty()).build();
return new SolrTemplate(cloudSolrClient);
}
}
创建一个
CloudSolrClient
Bean怎么样
@Bean
protected static CloudSolrClient SolrClient() {
String[] zkHosts = this.zkHost.split(",");
CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder(Arrays.asList(zkHosts), Optional.empty()).build();
return new CloudSolrClient(zkHostString);
}
并将其作为参数传递给SolrTemplate
如下:
@Bean
public SolrTemplate solrTemplate(CloudSolrClient cloudSolrClient) throws Exception {
return new SolrTemplate(cloudSolrClient);
}
然后关闭CloudSolrClient
,这很可能会终止模板
if(cloudSolrClient != null)
cloudSolrClient.close();
创建一个
CloudSolrClient
Bean怎么样
@Bean
protected static CloudSolrClient SolrClient() {
String[] zkHosts = this.zkHost.split(",");
CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder(Arrays.asList(zkHosts), Optional.empty()).build();
return new CloudSolrClient(zkHostString);
}
并将其作为参数传递给SolrTemplate
如下:
@Bean
public SolrTemplate solrTemplate(CloudSolrClient cloudSolrClient) throws Exception {
return new SolrTemplate(cloudSolrClient);
}
然后关闭CloudSolrClient
,这很可能会终止模板
if(cloudSolrClient != null)
cloudSolrClient.close();
检查这是否对Spring boot使用CommandLineRunner允许控制台应用程序有帮助。我的问题是关于SolrTemplate在程序结束时不退出。检查这是否有帮助Spring boot使用CommandLineRunner允许控制台应用程序。我的问题是关于SolrTemplate在程序结束时不退出。