整合完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. canvas的简单圆形进度条

    window.onload = function(){ function arc(canvas,number){ var canvas = document.getElementById(canvas ...

  2. VIM下的跳转练习

    在vim下可以使用常用的箭头键 但是 还有其它键可以让你更快的达到目标 hjkl 这是代替箭头键功能的 H M L 跳到屏幕的顶上 中间 下方 w 跳到下一个单词的开始e 跳到单词的结束b 向后跳 g ...

  3. Java 读写XML

    package dome4jTest; import java.io.FileWriter; import java.io.IOException; import java.net.URL; impo ...

  4. 导入excel数据到数据库

    1.上传excel到服务器 jsp页面代码 <form action="actionname" method="post" id="form1& ...

  5. WINFORM中的COMBOX模糊查询

    有的时候下拉框中的元素过多不好查询,可以考虑进行模糊过滤查询. 在类文件的designer.cs中找到定义combox的模块,加入以下两行代码即可: this.combox.AutoCompleteM ...

  6. AngularJS多模块开发

    angularJS中的多模块开发是指多个module模块开发,步骤为: 1. 确定主模块    var app=angular.module('myApp',[]); 2. 其他的子模块添加到主模块后 ...

  7. django上传图片

    django修改头像的功能... 1.在表单中加入enctype="multipart/form-data: 关于表单中enctype的介绍:http://www.w3school.com. ...

  8. Spring4.0编程式定时任务配置

    看过很多定时调度的配置,大多使用XML配置,觉得比较麻烦,也比较老套.这里介绍一种基于spring4.0注解编程式配置定时任务,简单清晰,使用方便.. 至于引入spring相关jar这里不多说,直接切 ...

  9. 提交form表单

    方法一: $.ajax({ }) $.ajax({ cache: true, type: "POST", url:ajaxCallUrl, data:$('#yourformid' ...

  10. jsp 中登录验证 注销 的模版

    用户名密码验证模版     <%@page import="com.jerehedu.bao.User"%> <%@ page language="ja ...