Spring给类中静态变量赋值
Posted zzm568599448
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring给类中静态变量赋值相关的知识,希望对你有一定的参考价值。
spring-context.xml中代码
<bean class="com.apricotforest.doctor.pocket.solrsearch.util.SolrUtils"
init-method="init">
<property name="solrServer" value="$solr_server"/>
</bean>
env.properties中代码
solr_server=http://localhost:8080/solr
SolrUtils.java中代码
package com.apricotforest.doctor.pocket.solrsearch.util;
import org.apache.solr.client.solrj.impl.BinaryRequestWriter;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
public class SolrUtils
private String solrServer;
private static SolrUtils solrUtils;
public static HttpSolrClient getHttpSolrClient()
HttpSolrClient httpSolrClient = new HttpSolrClient(solrUtils.solrServer);
httpSolrClient.setSoTimeout(10000);
httpSolrClient.setConnectionTimeout(5000);
httpSolrClient.setDefaultMaxConnectionsPerHost(1000);
httpSolrClient.setMaxTotalConnections(1000);
httpSolrClient.setFollowRedirects(false);
httpSolrClient.setAllowCompression(true);
httpSolrClient.setRequestWriter(new BinaryRequestWriter());
return httpSolrClient;
public void init()
solrUtils = this;
solrUtils.solrServer = this.solrServer;
public void setSolrServer(String solrServer)
this.solrServer = solrServer;
以上是关于Spring给类中静态变量赋值的主要内容,如果未能解决你的问题,请参考以下文章