- 浏览: 2551940 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Spring Boot and RESTful API(2)SOLR Repository
Install SOLR on local
>wget http://apache.mirrors.tds.net/lucene/solr/6.6.0/solr-6.6.0.zip
Unzip and place it in the right directory, Start the Server on Local
>bin/solr start -p 8984
Visit page
http://localhost:8983/solr/#/
But there is no core there, so I follow this link and try to create one core named collection1
https://stackoverflow.com/questions/38424574/how-to-create-solr-6-cores
>cd /opt/solr/server/solr
>mkdir job
>cp -r configsets/basic_configs/conf ./job/conf
Visit the UI - click on Add Core — Put name and instanceDir ‘job'
http://localhost:8983/solr/#/~cores
Click on Schema and ‘Add Field’ to add filed.
Fetch Content from SOLR
query documents
https://github.com/spring-projects/spring-data-solr
Some Dependencies on pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
POJO Job.java
package com.sillycat.jobsmonitorapi.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.annotation.Id;
import org.springframework.data.solr.core.mapping.SolrDocument;
@SolrDocument(solrCoreName = "job")
public class Job {
@Id
@Field
private String id;
@Field("source_id")
private Integer sourceID;
@Field("job_reference")
private String jobReference;
public Job() {
}
public Job(String id, Integer sourceID, String jobReference) {
super();
this.id = id;
this.sourceID = sourceID;
this.jobReference = jobReference;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getSourceID() {
return sourceID;
}
public void setSourceID(Integer sourceID) {
this.sourceID = sourceID;
}
public String getJobReference() {
return jobReference;
}
public void setJobReference(String jobReference) {
this.jobReference = jobReference;
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
JobRepositorySolr.java which is a interface
package com.sillycat.jobsmonitorapi.repository;
import java.util.List;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;
import com.sillycat.jobsmonitorapi.domain.Job;
public interface JobRepositorySolr extends SolrCrudRepository<Job, String> {
@Query(fields = { "job_reference" })
List<Job> findBySourceID(Integer sourceID);
}
Unit Tests for that Repository, JobRepositorySolrTest.java
package com.sillycat.jobsmonitorapi.repository;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.IteratorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Assert;
import com.sillycat.jobsmonitorapi.domain.Job;
@RunWith(SpringRunner.class)
@SpringBootTest
public class JobRepositorySolrTest {
@Autowired
JobRepositorySolr jobRepositorySolr;
@Test
public void save() throws Exception {
Job job1 = new Job("1", 9527, "9527_java");
Job job2 = new Job("2", 9527, "9527_nodejs");
jobRepositorySolr.save(job1);
jobRepositorySolr.save(job2);
}
@Test
public void queryBasic() throws Exception{
Iterator<Job> jobsIt = jobRepositorySolr.findAll().iterator();
@SuppressWarnings("unchecked")
List<Job> jobs = IteratorUtils.toList(jobsIt);
Assert.notEmpty(jobs, "Fail to fetch anything from SOLR");
}
@Test
public void queryBySourceID() throws Exception{
List<Job> jobs = jobRepositorySolr.findBySourceID(9527);
Assert.notEmpty(jobs, "Fail to queryBySourceID from SOLR");
List<Job> jobEmptys = jobRepositorySolr.findBySourceID(9529);
Assert.isTrue(jobEmptys.isEmpty(), "Fail to filter out other sourceID");
}
}
References:
http://projects.spring.io/spring-data-solr/
https://github.com/spring-projects/spring-data-solr
http://www.jianshu.com/p/e21fe5f3bd8c
http://www.kailing.pub/article/index/arcid/150.html
http://www.kailing.pub/article/index/arcid/150.html
http://docs.spring.io/spring-data/solr/docs/3.0.0.M3/reference/html/
Install SOLR on local
>wget http://apache.mirrors.tds.net/lucene/solr/6.6.0/solr-6.6.0.zip
Unzip and place it in the right directory, Start the Server on Local
>bin/solr start -p 8984
Visit page
http://localhost:8983/solr/#/
But there is no core there, so I follow this link and try to create one core named collection1
https://stackoverflow.com/questions/38424574/how-to-create-solr-6-cores
>cd /opt/solr/server/solr
>mkdir job
>cp -r configsets/basic_configs/conf ./job/conf
Visit the UI - click on Add Core — Put name and instanceDir ‘job'
http://localhost:8983/solr/#/~cores
Click on Schema and ‘Add Field’ to add filed.
Fetch Content from SOLR
query documents
https://github.com/spring-projects/spring-data-solr
Some Dependencies on pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
POJO Job.java
package com.sillycat.jobsmonitorapi.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.annotation.Id;
import org.springframework.data.solr.core.mapping.SolrDocument;
@SolrDocument(solrCoreName = "job")
public class Job {
@Id
@Field
private String id;
@Field("source_id")
private Integer sourceID;
@Field("job_reference")
private String jobReference;
public Job() {
}
public Job(String id, Integer sourceID, String jobReference) {
super();
this.id = id;
this.sourceID = sourceID;
this.jobReference = jobReference;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getSourceID() {
return sourceID;
}
public void setSourceID(Integer sourceID) {
this.sourceID = sourceID;
}
public String getJobReference() {
return jobReference;
}
public void setJobReference(String jobReference) {
this.jobReference = jobReference;
}
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
JobRepositorySolr.java which is a interface
package com.sillycat.jobsmonitorapi.repository;
import java.util.List;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;
import com.sillycat.jobsmonitorapi.domain.Job;
public interface JobRepositorySolr extends SolrCrudRepository<Job, String> {
@Query(fields = { "job_reference" })
List<Job> findBySourceID(Integer sourceID);
}
Unit Tests for that Repository, JobRepositorySolrTest.java
package com.sillycat.jobsmonitorapi.repository;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.IteratorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Assert;
import com.sillycat.jobsmonitorapi.domain.Job;
@RunWith(SpringRunner.class)
@SpringBootTest
public class JobRepositorySolrTest {
@Autowired
JobRepositorySolr jobRepositorySolr;
@Test
public void save() throws Exception {
Job job1 = new Job("1", 9527, "9527_java");
Job job2 = new Job("2", 9527, "9527_nodejs");
jobRepositorySolr.save(job1);
jobRepositorySolr.save(job2);
}
@Test
public void queryBasic() throws Exception{
Iterator<Job> jobsIt = jobRepositorySolr.findAll().iterator();
@SuppressWarnings("unchecked")
List<Job> jobs = IteratorUtils.toList(jobsIt);
Assert.notEmpty(jobs, "Fail to fetch anything from SOLR");
}
@Test
public void queryBySourceID() throws Exception{
List<Job> jobs = jobRepositorySolr.findBySourceID(9527);
Assert.notEmpty(jobs, "Fail to queryBySourceID from SOLR");
List<Job> jobEmptys = jobRepositorySolr.findBySourceID(9529);
Assert.isTrue(jobEmptys.isEmpty(), "Fail to filter out other sourceID");
}
}
References:
http://projects.spring.io/spring-data-solr/
https://github.com/spring-projects/spring-data-solr
http://www.jianshu.com/p/e21fe5f3bd8c
http://www.kailing.pub/article/index/arcid/150.html
http://www.kailing.pub/article/index/arcid/150.html
http://docs.spring.io/spring-data/solr/docs/3.0.0.M3/reference/html/
发表评论
-
Update Site will come soon
2021-06-02 04:10 1678I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 455VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 356Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 405PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 720Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 295Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 294Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 241MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 294MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 325Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 312Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 332Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 283Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 326K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 362Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 444Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 373Redis Cluster 2019(3)Redis Clus ...
相关推荐
免费的学习视频,比网上骗人那些强多了,希望对大家有帮助。如果没有账号的注册一下就可以了
### Spring Boot开发实战:基于Spring Boot的RESTful API服务的实验心得与案例解析 #### 一、引言 Spring Boot自发布以来,以其强大的自动配置能力、简洁的开发模式以及丰富的社区支持,迅速成为了Java开发者构建...
**Spring Boot RESTful API Demo** 在现代Web开发中,RESTful API已经成为构建可扩展、松耦合服务的主要方式。Spring Boot作为Java生态系统中的一个强大框架,简化了创建生产级的基于Spring的应用程序。本示例将...
为了解决上面这样的问题,本文将介绍RESTful API的重磅好伙伴Swagger2,它可以轻松的整合到Spring Boot中,并与Spring MVC程序配合组织出强大RESTful API文档。它既可以减少我们创建文档的工作量,同时说明内容又...
3. 接下来,我们需要实现Restful API和WebService API接口,使用Spring Boot的Restful API和CXF框架来实现学生信息的增删改查操作。 4. 最后,我们需要测试Restful API和WebService API接口,确保其正常工作。 结论...
该项目提供基于Java和Spring Boot框架构建的RESTful API设计与调用源码,涵盖17个Java源文件、9个XML配置文件、6个JavaScript文件、4个CSS样式文件、2个HTML文件,共计46个文件。项目旨在实现Spring Boot的API发布与...
本文主要介绍了通过使用 Maven Archetype 与 Spring Boot 能够迅速搭建起一个支持CRUD的基本RESTful API项目框架,并提供了从创建初始项目到完成简易数据操作(如增删查)的具体指南和代码样例。 适合具有一定经验但...
内容概要:本文详述了如何利用Spring Boot技术搭建一套简易图书管理系统的RESTful API接口流程,涵盖从初始创建到实现完整CRUD(增删改查)功能的整体步骤,并提供H2内存数据库作为数据存储支持。此外介绍了系统主要...
Spring Boot 整合 Mybatis 实现RESTful API ,具体可以查看博客: http://blog.csdn.net/yaozhiqi1905658804/article/details/70820892
在Spring Boot项目中集成Swagger2,可以帮助我们快速地构建和维护高质量的RESTful API。以下将详细讲解如何利用Spring Boot与Swagger2进行集成,并展示其主要功能和步骤。 **一、集成Swagger2** 1. 添加依赖:首先...
在 Spring Boot 中构建 RESTful API,主要涉及以下几个关键知识点: 1. **MVC 模式**:Spring Boot 基于 Spring MVC 框架提供了一种简洁的 Web 开发方式。你可以使用 `@RestController` 注解标记控制器类,而 `@...
内容概要:详细介绍使用Java、Spring Boot以及相关技术和工具如Maven、H2 database搭建简单的图书管理RESTful API系统全过程,覆盖了从项目的建立、实体类定义、接口编写一直到API的功能测试。项目主要提供了增加、...
在这个“Spring Boot RESTful 接口示例项目”中,我们可以学习到如何使用 Spring Boot 创建 RESTful 风格的 API。RESTful API 通常通过 HTTP 协议提供服务,利用 GET、POST、PUT、DELETE 等方法操作资源,实现客户端...
而Swagger是目前最流行的接口文档解决方案,本文主要通过代码实战的方式讲解Spring Boot 和Swagger集成生成Restful接口文档。教程参见 http://blog.csdn.net/zjx2016/article/details/74407832
基于Spring Boot,采用RESTful风格架构的微信点餐系统源码(高分毕设).zip 基于Spring Boot,采用RESTful风格架构的微信点餐系统源码(高分毕设).zip 基于Spring Boot,采用RESTful风格架构的微信点餐系统源码...
2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; ...
基于 Spring Boot 的 Restful 风格实现增删改查
Spring Boot实现Restful并对数据库CRUD操作的示例 同时使用了Spring Data JPA,需先创建MySQL数据库名为springbootdb, 数据库表会自动创建(Hibernate开启了ddl-auto:update) 数据库配置参见项目/src/main/...
Spring Boot 2.x基础教程:构建RESTful API与单元测试 Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档 Spring Boot 2.x基础教程:JSR-303实现请求参数校验 Spring Boot 2.x基础教程:Swagger接口分类与各...