整合完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的更多相关文章

  1. springboot+solr基本使用

    接着上一篇的搭建 首先需要的pom节点有 <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data ...

  2. solr8.0 springboot整合solr(四)

    引言: solr搭建起后,就该应用到java后台开发里了,接下来就用springboot整合应用solr 一:引入jar包 <!--solr--> <dependency> & ...

  3. springboot整合solr

    上一篇博客中简要写了solr在windows的安装与配置,这一篇接上文写一下springboot整合solr,代码已经上传到github,传送门. 1.新建core并配置schema 上篇博客中已经有 ...

  4. Springboot与ActiveMQ、Solr、Redis中分布式事物的初步探索

    Springboot与ActiveMQ.Solr.Redis中分布式事物的初步探索 解决的场景:事物中的异步问题,当要求数据库与solr服务器的最终一致时. 程序条件: 利用消息队列,当数据库添加成功 ...

  5. springboot和solr结合测试使用

    首先新建springboot项目 新建webapp目录 springboot没有webapp目录——手动添加 web.xml <?xml version="1.0" enco ...

  6. solr(四) : springboot 整合 solr

    前言: solr服务器搭起来, 数据导入之后, 就该应用到项目中去了. 那在项目中, 该怎么整合和应用solr呢? 接下来, 就来整合和应用solr 一. 整合 1. 引入jar包 <prope ...

  7. SpringBoot整合Spring Data Solr

    此文不讲solr相关,只讲整合,内容清单如下 1. maven依赖坐标 2. application.properties配置 3. Java Config配置 1. maven坐标 <depe ...

  8. SpringBoot前世今生

    序 本文主要讲述spring boot的由来,即其它诞生的背景,初衷,现状,及对未来的展望. 背景 在很早的年代,J2EE还是java企业级应用的王者规范,EJB风行其道.后来有一个叫Rod John ...

  9. 使用spring-data-solr做solr客户端

    solr的客户端基本上只有一个,那就是solrj,spring-data-solr是在solrj的基础上做的封装,使统一成spring-data的风格 官方网站: http://projects.sp ...

随机推荐

  1. ASM,C数据类型

    汇编: db  单字节 = 8bit dw 单字    = 16bit dd  双字   = 32bit C数据类型: char                字节 8bit unsigned cha ...

  2. python3 爬虫

    保存当前cookie到本地 import urllib.request as ur import http.cookiejar as hc url='http://www.xxxx.com/admin ...

  3. 正则表达式工具RegexBuddy使用教程

    1. 界面介绍  (1)初始界面选项介绍 (2)如何使用匹配 (3)如何使用正则替换 (4)如何使用Debug http://www.cnblogs.com/tsql/p/5860893.html

  4. JDBC连接数据库演示案例

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...

  5. 出现个Expression(str != NULL)

    CPrimerPlus的11章复习题10:编写个函数,其参数为一个字符串指针,返回一个指针,返回的指针指向字符串中第一个空格的位置(如果没有空格就返回空指针) #include <stdio.h ...

  6. 【python】类(资料+疑惑)

    1.http://python-china.org/t/77 有关method binding的理解 2.[Python] dir() 与 __dict__,__slots__ 的区别 3.Descr ...

  7. hadoop2的思想架构

    mapreduce 2 思想架构 mr2解决了mr1的jobTracker的单点颈瓶问题,这个问题会影响hadoop的扩展性,集群的可靠性,mr1中jobTracker负责集群作业的分发,管理,调度, ...

  8. spring mvc 请求转发和重定向(转)

    spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...

  9. 牛B的调试工具:OzCode

      官网:http://www.oz-code.com/ 视频:https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/OzCode https:/ ...

  10. 与你相遇好幸运,Sailsjs查询

    sailsjs 原生查询 ------------------------------------- Lands.native(function(err, collection) { if (err) ...