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 ...
随机推荐
- Visual Studio常用快捷键
1. 代码自动对齐:CTRL+K+F 2. 撤销---使用组合键“Ctrl+Z”进行撤销操作 3. 反撤销---使用组合键“Ctrl+Y”进行反撤销操作 4. 使用组合键“Ctrl+J”或者使用组合键 ...
- sdcms留言提交
引入这两个js <script src="{webroot}lib/validator/jquery.validator.js"></script>< ...
- python FileError
>>> ls1=["nihia"] >>> ls1 ['nihia'] >>> ls1.pop() 'nihia' >& ...
- python之路九
paramiko paramiko模块是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接 ssh执行命令: import paramikossh = pa ...
- October 21st 2016 Week 43rd Friday
Life is too short for long-term grudges. 人生苦短,无暇怨恨. Don't limit yourself. You can go as far as your ...
- 【控制iOS7兼容iOS6 状态栏的显示不完全 简单缩写】
#if ios7 self.automaticallyAdjustsScrollViewInsets = YES; self.edgesForExtendedLayout = UIRectEdgeNo ...
- Power BI FAQ
关于Power BI,最近一直想写点什么,但是也想不到写什么.直到前几天,有个朋友在qq加我,问了我好几个问题,我发现都是一些很有代表性的问题,所以都记录了下来,特意整理了一下分享出来,希望能帮到更多 ...
- WinForm/MIS项目开发之中按钮级权限实践
一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...
- IBatis.Net使用总结(二)-- IBatis返回DataTable/DataSet(网上例子的集合)
IBatis返回DataTable,DataSet ibatis.net QueryForDataTable 完整的为ibatis.net 引入datatable支持要改动很多地方,所以描述的是最小化 ...
- Java基础知识点1:基本类型包装类
基本类型的包装类 简介 通常来说我们在程序中经常会使用元类型,比如 int data = 1; float data = 2.1F; 但是在有些场景中不能直接使用元类型,比如如果我们想要建立一个int ...