先写一个测试类:

 package com.taotao.rest.solrj;

 import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test; public class SolrJTest { public static final String BASE_URL = "http://192.168.83.133:8080/solr/collection1";
@Test
public void addDocument() throws Exception {
//创建一个连接
SolrClient solrClient = new HttpSolrClient.Builder(BASE_URL).withConnectionTimeout(1000).withSocketTimeout(6000).build();
//创建一个文档对象
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "test001");
document.addField("item_title", "测试商品2");
document.addField("item_price", 123456);
//把文档对象写入索引库
solrClient.add(document);
//提交
solrClient.commit();
} @Test
public void delete() throws Exception{
// 创建一个连接
SolrClient solrClient = new HttpSolrClient.Builder(BASE_URL).withConnectionTimeout(1000).withSocketTimeout(6000).build();
//solrClient.deleteById("test001");
solrClient.deleteByQuery("*:*");
solrClient.commit();
}
}

说明:最新版的jar包中已经没有SolrServer这个类了,取而代之的是SolrClient。

通过URL操作Solr:

resource.properties:

 #solr服务地址
SOLR.SERVER.URL=http://192.168.83.133:8080/solr/collection1

spring 中的 applicationContext-solr.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 配置SolrServer对象 -->
<!-- 单机版 -->
<bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrClient">
<constructor-arg name="builder" value="${SOLR.SERVER.URL}"></constructor-arg>
</bean>
</beans>

说明:使用时注意版本。

Eclipse使用solrJ 7.7.0连接solr步骤的更多相关文章

  1. Eclipse 下配置MySql5.6的连接池,使用Tomcat7.0

    目前找到的最简单的配置方法.   1.首先在eclipse中创建一个Dynamical Web Application,在WebContent文件夹下的META-INF文件夹中创建新的名为conten ...

  2. C#连接solr时提示 java内存异常 (jetty和tomcat哪个更High) java.lang.OutOfMemoryError

    C#连接solr时提示 java内存异常   java.lang.OutOfMemoryError 时间:20180130 09:51:13.329,消息:异常消息<?xml version=& ...

  3. 使用SolrJ客户端管理SolrCloud(Solr集群)

    1.使用SolrJ客户端管理SolrCloud(Solr集群). package com.taotao.search.service; import java.io.IOException; impo ...

  4. Eclipse中部署hadoop2.3.0

    1 eclipse中hadoop环境部署概览 eclipse 中部署hadoop包括两大部分:hdfs环境部署和mapreduce任务执行环境部署.一般hdfs环境部署比较简单,部署后就 可以在ecl ...

  5. Mysql6.0连接中的几个问题 Mysql6.xx

    Mysql6.0连接中的几个问题 在最近做一些Javaweb整合时,因为我在maven官网查找的资源,使用的最新版,6.0.3,发现MySQL连接中的几个问题,总结如下: 1.Loading clas ...

  6. mysql(8.0连接navicat发生的错误解决方法)

    关于mysql(8.0连接navicat发生的错误解决方法)数据库安装图形化界面无法更改加密的方式导致无法连接问题为解决; Alter user 'root'@'localhost' identifi ...

  7. Windows Tomcat7.0 安装 Solr

    准备工作 1.下载Tomcat7.0 ,apache-tomcat-7.0.67.exe,安装目录如下:C:\workspace\Tomcat7.0\ 2.下载Solr 5.2,solr-5.2.0. ...

  8. Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤

    原文地址: Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤 - 网络资源是无限的 - 博客频道 - CSDN.NET http://blog.csdn.net/fen ...

  9. VB6.0连接MySQL数据库

    VB6.0连接MySQL数据库

随机推荐

  1. layer.open窗口自适应问题

    宽高度 area : ['100%', '100%']同时取消layer.full(index)就能自适应

  2. 不通过百川打开淘宝app

    private void openTaobao(String url){ if (isAppInstalled(this, "com.taobao.taobao")) { //这行 ...

  3. python测试断言

    这几天看了一下python的测试,基于函数方法和基于类的测试,主要使用的模块是unittest模块,为特定的方法和类,建立测试模块,测试函数功能是否满足预期.下面是模仿书里面的一个例子. City.p ...

  4. Luogu P4484 [BJWC2018]最长上升子序列

    状压\(DP\)+打表,要命的题目..... 具体思路请参考这位巨佬的博客,本蒟蒻对这道题感到心力交瘁,决定不再作出补充.. 关键的要学习的是:对于排列问题,从左到右处理比较困难的话,考虑从小到大把数 ...

  5. 2018ccpc秦皇岛站后记

    总的来说这不是一场体验十分好的比赛. 定的宾馆有一点小,学校提供的伙食人太多了,不想排队,饭票又不能换香蕉,就没有吃. 到的第一天遇到了价格向上取整和到站不打发票的两个黑车司机,让我对这个地点好感大减 ...

  6. Hbase准生产配置

    hbase-site.xml <?xml version="1.0"?><?xml-stylesheet type="text/xsl" hr ...

  7. 虚拟机部署hadoop集群准备工作之多虚拟机设置网络信息

    安装好了centos6.4(最简版)后   1,静态IP设置 查看虚拟机的网络设置信息来配置

  8. scrapy_splash模块解析动态js

    一般遇到动态加载的网页就比较棘手,一般采用scrapy_splash和selenium这两种方式来解决.貌似scrapy_splash更强大,因为就从爬取美团这个网站而言,scrapy_splash可 ...

  9. Mac下显示网页全屏快捷键

    control+command+F mac下谷歌浏览器全屏时隐藏头部:(隐藏标签页和地址栏) command+shift+B

  10. redis做session会话共享

    项目中需要两个不同的web项目互相访问,用户对象为同一个User.决定用Redis来存储用户对象信息...ok,环境搭建开始: 1.pom.xml引入Redis依赖的jar: <!-- jedi ...