org.springframework.data.solr.UncategorizedSolrException: Expected mime type application/octet-strea

学习Solr写Demo时,服务器报错

后端代码:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-solr.xml")
public class TestTemplate {

	@Autowired
	private SolrTemplate solrTemplate;

	@Test
	public void testAdd() {
		TbItem item = new TbItem();
		// 主键相同,即修改
		item.setId(1L);
		item.setBrand("小米儿");
		item.setCategory("手机");
		item.setGoodsId(1L);
		item.setSeller("谁**买小米儿");
		item.setTitle("新鲜的小米儿只要998");
		item.setPrice(new BigDecimal(998));
		
		solrTemplate.saveBean(item);
		solrTemplate.commit();
	}
	
}

错误详情:

org.springframework.data.solr.UncategorizedSolrException: Expected mime type application/octet-stream but got text/html.
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 405 HTTP method POST is not supported by this URL</title>
</head>
<body><h2>HTTP ERROR 405</h2>
<p>Problem accessing /solr/index.html. Reason:
<pre>    HTTP method POST is not supported by this URL</pre></p>
</body>
</html>
; nested exception is org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Expected mime type application/octet-stream but got text/html. 

解决方法:
  修改配置文件spring-solr.xml,url地址里的 /# 删掉

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:solr="http://www.springframework.org/schema/data/solr"
	xsi:schemaLocation="http://www.springframework.org/schema/data/solr 
  		http://www.springframework.org/schema/data/solr/spring-solr.xsd
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd">
		
	<!-- 错误的solr服务器地址 -->
	<!-- <solr:solr-server id="solrServer" 
		url="http://192.168.188.102:8983/solr/#/collection1" /> -->
	<!-- 正确的solr服务器地址 -->
	<solr:solr-server id="solrServer" 
		url="http://192.168.188.102:8983/solr/collection1" />
		
	<!-- solr模板,使用solr模板可对索引库进行CRUD操作 -->
	<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
		<constructor-arg ref="solrServer" />
	</bean>
	
</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值