先写一个测试类:

 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. c#反射(2)

    public void Test1() { string ClassName="Person"; string MethodName="Test1"; //得到 ...

  2. Python继承扩展内置类

    继承最有趣的应用是给内置类添加功能,在之前的Contact类中,我们将联系人添加到所有联系人的列表里,如果想通过名字来搜索,那么就可以在Contact类添加一个方法用于搜索,但是这种方法实际上属于列表 ...

  3. layui基础总结

    1.layui结构 ├─css //css目录      │  │─modules //模块css目录(一般如果模块相对较大,我们会单独提取,比如下面三个:)      │  │  ├─laydate ...

  4. GitHub合并(merge)代码时冲突解决

    1.手动merge-->消除冲突-->然后commit,push 2.每次合并代码之前需要从远程主分支上拉取代码, 3.使用git命令行解决冲突. 新手可参考一些博客https://www ...

  5. 1.Eureka

    分布式系统中,当B的数量越来越多的时候,A只需要从注册中心获取B注册的服务,而不需要直接从B中获取服务,答案显而易见. application.yml: eureka: client: service ...

  6. MySQL数据库权限体系介绍

    本文主要向大家介绍了MySQL数据库权限体系,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 一.权限体系简介: MySQL的权限体系在实现上比较简单,相关权限信息主要存储在mys ...

  7. HDU 1284(钱币兑换 背包/母函数)

    与 HDU 1028 相似的题目. 方法一:完全背包. 限制条件:硬币总值不超过 n. 目标:求出组合种数. 令 dp[ i ][ j ] == x 表示用前 i 种硬币组合价值为 j 的钱共 x 种 ...

  8. 绕不开的hadoop

    安装 jdk 1.8 # 官网下载可能比较慢,请自行搜索国内镜像源 wget http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a ...

  9. 在CentOS7上安装Zabbix3.0

    #!/bin/bash # # .配置无人值守的安装,定义安装过程中需要用到的一些信息 # mysql_root_pw=root_pw mysql_zabbix_pw=zabbix_pw DBPass ...

  10. Bitcoin Core钱包客户端的区块数据搬家指南

    最近在饭团(微信中的一个服务号)里教一些朋友学习比特币和区块链技术,为了让大家深刻地理解去中心化网络和钱包等概念,我推荐大家一定要安装经典的Bitcoin Core钱包软件,有些朋友在安装的时候没有留 ...