[solr ] solrj 在tomcat下不能添加数据 报错

tanjunxiaoge 2010-05-27
使用solrj时出现以下问题:
Exception in thread "main" org.apache.solr.common.SolrException: Bad Request

Bad Request

request: http://localhost:8080/solr/update?wt=javabin&version=1

另外:“http://localhost:8080/solr”能够正常访问
原码如下:

public class test1 {
public static final String SOLR_URL = "http://localhost:8080/solr";

public static void commit() {
Date date = new Date();
CommonsHttpSolrServer server = null;
try {
server = new CommonsHttpSolrServer(SOLR_URL);

} catch (MalformedURLException e1) {
e1.printStackTrace();
}
for (int i = 0; i < 10000; i++) {
SolrInputDocument sid = new SolrInputDocument();
sid.addField("id", i);
sid.addField("name", "struts+hibernate+spring 开发大全" + i);

sid.addField("author", "李良杰" + i);

try {
server.add(sid);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(i);
if (i %999==0)
System.out.println((new Date().getTime() - date.getTime())
/ 60000.0 + "分钟-------------------------------------");
}
try {
server.commit();
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

commit();
}
Global site tag (gtag.js) - Google Analytics