配置是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方法通过的办法。
solrClient is not null
String solrUrl="http://127.0.0.1:8080/solr/index.html/core_demo"; 这个地址有没有开启?
我也出现了类似的问题:
我的处理方式:
1、solrUrl="http://127.0.0.1:8080/solr/core_demo”改为这个路径(不管是solr7.X还是solr4.X都已经验证是该路径)。
2、查看你的solr服务器里面的配置文件(solr7.X配置managed-schema ,solr4.X的为schema.xml)我在配置自定义Filed时少配置了一个属于,
浏览器可访问但是程序一直无法调通。
加上配置后程序
正常运行。