springboot+solr
整合完DB层,cache层,开始整合solr。
注入SolrClient,
package hello.configuration; import java.net.MalformedURLException; import javax.annotation.Resource; import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.repository.config.EnableSolrRepositories; @Configuration
@EnableSolrRepositories(multicoreSupport = true)
@PropertySource(value = "classpath:/solr.properties")
public class SolrConfiguration { private static final String SOLR_HOST = "solr.host"; @Resource
private Environment environment; @Bean
public SolrClient solrServer() throws MalformedURLException {
String solrHost = environment.getRequiredProperty(SOLR_HOST);
return new LBHttpSolrClient(solrHost);
}
}
solr.properties配置文件
solr.host=http://localhost:7574/solr/gettingstarted_shard1_replica1
solr测试类
package hello.test; import java.io.IOException; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.springframework.stereotype.Component; @Component
public class SolrBean { @Resource
private SolrClient solrClient; // @Resource
// private SolrProductRepository solrProductRepository; public void run() throws SolrServerException, IOException {
// Iterable<Product> productList = solrProductRepository.findAll();
// while (productList.iterator().hasNext()) {
// Product product = (Product) productList.iterator().next();
// System.out.println("solr获取值:" + product.getId());
// }
} @PostConstruct
public void run2() throws SolrServerException, IOException {
SolrQuery query = new SolrQuery();// 查询
query.setQuery("id:123");
QueryResponse response = solrClient.query(query);
SolrDocumentList solrDocumentList = response.getResults();
for (SolrDocument sd : solrDocumentList) {
System.out.println("solr获取值:" + sd.getFieldValue("id"));
System.out.println("solr获取值:" + sd.getFieldValue("title"));
}
}
}
springboot+solr的更多相关文章
- springboot+solr基本使用
接着上一篇的搭建 首先需要的pom节点有 <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data ...
- solr8.0 springboot整合solr(四)
引言: solr搭建起后,就该应用到java后台开发里了,接下来就用springboot整合应用solr 一:引入jar包 <!--solr--> <dependency> & ...
- springboot整合solr
上一篇博客中简要写了solr在windows的安装与配置,这一篇接上文写一下springboot整合solr,代码已经上传到github,传送门. 1.新建core并配置schema 上篇博客中已经有 ...
- Springboot与ActiveMQ、Solr、Redis中分布式事物的初步探索
Springboot与ActiveMQ.Solr.Redis中分布式事物的初步探索 解决的场景:事物中的异步问题,当要求数据库与solr服务器的最终一致时. 程序条件: 利用消息队列,当数据库添加成功 ...
- springboot和solr结合测试使用
首先新建springboot项目 新建webapp目录 springboot没有webapp目录——手动添加 web.xml <?xml version="1.0" enco ...
- solr(四) : springboot 整合 solr
前言: solr服务器搭起来, 数据导入之后, 就该应用到项目中去了. 那在项目中, 该怎么整合和应用solr呢? 接下来, 就来整合和应用solr 一. 整合 1. 引入jar包 <prope ...
- SpringBoot整合Spring Data Solr
此文不讲solr相关,只讲整合,内容清单如下 1. maven依赖坐标 2. application.properties配置 3. Java Config配置 1. maven坐标 <depe ...
- SpringBoot前世今生
序 本文主要讲述spring boot的由来,即其它诞生的背景,初衷,现状,及对未来的展望. 背景 在很早的年代,J2EE还是java企业级应用的王者规范,EJB风行其道.后来有一个叫Rod John ...
- 使用spring-data-solr做solr客户端
solr的客户端基本上只有一个,那就是solrj,spring-data-solr是在solrj的基础上做的封装,使统一成spring-data的风格 官方网站: http://projects.sp ...
随机推荐
- 【Python基础学习四】字符串(string)
Python 字符串 字符串是 Python 中最常用的数据类型.可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可.例如: var1 = 'hello' va ...
- Oracle生成指定表的列名,并前后添加select from
表的列名比较多的时候,手工一个个的写列名比较麻烦,这个函数可以让人偷偷懒 create or replace function f_GetCols(p_TableName in varchar2/*获 ...
- SQL操作记录查看工具
[1]SQL Server Profiler就是一个Sql的监视工具,可以具体到每一行Sql语句,每一次操作,和每一次的连接 [2] 做数据交互时,往往很难直观的看到最后在数据库中执行的SQL语句.此 ...
- linux操作oracle
1.su - oracle 2.sqlplus / as sysdba; 1.登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切换成oracle用 ...
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...
- javascript推荐书籍
本文转载自http://www.cnblogs.com/zfc2201/archive/2012/07/22/2604236.html感谢作者 WEB前端研发工程师,在国内算是一个朝阳职业,这个领域没 ...
- 【学习笔记】ES6标准入门
这里简要记录一下对自己感触比较深的几个知识点,将核心的应用投放于实际的项目之中,提供代码的可维护性. 一.let和const { // let声明的变量只在let命令所在的代码块内有效 let a = ...
- python_配置
代码示例:https://pan.baidu.com/s/1pLjLPSv 1.自动补全功能 许多人都知道 iPython 有很好的自动补全能力,但是就未必知道 python 也同样可以 Tab 键补 ...
- php多进程
增加 pcntl扩展pcntl扩展可以支持php的多线程操作(仅限linux系统)加载 pcntl 有两种方式一种重新编译安装,在编译时加,configrue提示加上--enable-pcntl./c ...
- haproxy 实现多域名证书https
[root@ha02 keys]# openssl genrsa - Generating RSA bit long modulus ....+++ ......................... ...