zoukankan      html  css  js  c++  java
  • SpringBoot整合Spring Data Solr

    此文不讲solr相关,只讲整合,内容清单如下

    1. maven依赖坐标

    2. application.properties配置

    3. Java Config配置

    
    

    1. maven坐标

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-solr</artifactId>
    </dependency>


    2. application.properties配置

    注意,这里的 spring.data.solr.core 不是框架提供的,在idea中会提醒

    # solr
    spring.data.solr.host=http://localhost:8080/solr
    spring.data.solr.core=collection1

    3. Java Config配置

    这里主要是配置一下SolrTemplate,默认情况下 solr的starter是不提供这个bean的。

    注意的地方就是HttpSolrServer要导对包

    import org.apache.solr.client.solrj.impl.HttpSolrServer;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.solr.core.SolrTemplate;
    import org.springframework.data.solr.core.convert.SolrJConverter;


    @Configuration
    public class SolrConfig {
    @Value("${spring.data.solr.host}")
    private String solrHost;

    @Value("${spring.data.solr.core}")
    private String solrCore;

    /**
    * 配置SolrTemplate
    */
    @Bean
    public SolrTemplate solrTemplate() {
    HttpSolrServer solrServer = new HttpSolrServer(solrHost);
    SolrTemplate template = new SolrTemplate(solrServer);
    template.setSolrCore(solrCore);
    // 2018-03-12晚更新,此处不需要加这句话,反而加了之后会导致solr域和实体类字段不同名时,导致无法将值映射到实体类字段中,此时会抛出异常,所以这里不需要加下面这句话
    // template.setSolrConverter(new SolrJConverter());
    return template;
    }
    }
    
    
  • 相关阅读:
    Oracle函数应用与查询聚合统计
    Oracle子查询与分页查询
    DB2端口(转自百度文库http://wenku.baidu.com/view/47809b26aaea998fcc220e65.html)
    职场生涯
    git 管理多个私钥
    ubuntu 解压 windows 生成的 zip 文件乱码问题
    js实现类似于add(1)(2)(3)调用方式的方法
    webkit内核浏览器的CSS写法
    python 单例模式
    Javascript模块化编程:AMD规范及require.js用法【转】
  • 原文地址:https://www.cnblogs.com/kazetotori/p/8549458.html
Copyright © 2011-2022 走看看