我在用solrj写一个简单的添加索引的测试方法报错 20C

配置是jdk1.8,tomcat9,solr6.6.2,myEclipse2016 ci。
测试方法是
@Test
public void testAdd(){
final String solrUrl="http://127.0.0.1:8080/solr/index.html/core_demo";
HttpSolrClient solrClient = new HttpSolrClient(solrUrl);
//SolrClient solrClient = new HttpSolrClient.Builder(solrUrl).build();
if(solrClient==null)
System.out.println("solrClient is null");
else
System.out.println("solrClient is not null");
SolrInputDocument doc = new SolrInputDocument();
try {
doc.addField("id", "12");
doc.addField("business_name", "哇哈哈");
doc.addField("business_type", "饮料");
doc.addField("business_description", "国产饮料");
solrClient.add(doc);
solrClient.commit();
System.out.println("添加成功");
} catch (Exception e) {
System.out.println("添加失败");
e.printStackTrace();

}
}
结果是
log4j:WARN No appenders could be found for logger (org.apache.solr.client.solrj.impl.HttpClientUtil).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
solrClient is not null
添加失败
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException:
Error from server at http://127.0.0.1:8080/solr/index.html/core_demo:
Expected mime type application/octet-stream but got text/html.
<!doctypehtml>

HTTP Status 404 – Not Found h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a{color:black;}a.name{color:black;}.line{height:1px;background-color:#525D76;border:none;}

HTTP Status 404 – Not Found



Type Status Report

Message /solr/index.html/core_demo/update

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


Apache Tomcat/9.0.0.M26


at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:580)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279)
at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:160)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:173)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:138)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:152)
at com.it.solrj.SolrJManger.testAdding(SolrJManger.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
我用的Junit测试的,它报错说多出了一个html文件,请问我在哪能找到这个文件,还有该怎么办?非常感谢。还有请教能让junit方法通过的办法。

1个回答

solrClient is not null
String solrUrl="http://127.0.0.1:8080/solr/index.html/core_demo"; 这个地址有没有开启?

kk3239226441
kk3239226441 http://127.0.0.18080/solr/index.html#/core_demo这个地址可以打开,但是还是报一样的错误。solr界面都是可以进去的。
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问