SpringBoot(2.0.4.RELEASE)+Elasticsearch(6.2.4)+Gradle简单整合
记录一下SpringBoot(2.0.4.RELEASE)+Elasticsearch(6.2.4)+Gradle整合的一个小例子。
1.在Gradle内加入相关jar包的依赖:
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
//添加Spring Data Elasticsearch依赖
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
//添加JNA依赖
compile('net.java.dev.jna:jna:4.3.0')
compile('com.google.guava:guava:26.0-jre')
2.创建实体对象,并加入Elasticsearch的相关注释:
package com.wey.pojo.blog; import java.io.Serializable;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; @Document(indexName="blogcenter",type="blog")
//indexName索引名称 可以理解为数据库名 必须为小写不然会报
public class Blog implements Serializable{ private static final long serialVersionUID = 1L; @Id
private String id;
private String title;
private String summary;
private String content; protected Blog() {
super();
} public Blog(String title, String summary, String content) {
this.title = title;
this.summary = summary;
this.content = content;
} public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getSummary() {
return summary;
} public void setSummary(String summary) {
this.summary = summary;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} @Override
public String toString() {
return "Blog [id=" + id + ", title=" + title + ", summary=" + summary + ", content=" + content + "]";
}
}
3.创建Repository
package com.wey.repository; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component; import com.wey.pojo.blog.Blog; public interface BlogRepository extends ElasticsearchRepository<Blog, String> {
}
4.创建Controller并简单的实现添加及查询
@RestController
@RequestMapping("/blogs")
public class BlogController {
@Autowired
BlogRepository blogRepository; @RequestMapping("/add")
public Blog add(Blog blog) {
return blogRepository.save(blog);
} @GetMapping
public List<Blog> findAll(){
Iterable<Blog> elements = blogRepository.findAll();
ArrayList<Blog> list = Lists.newArrayList(elements);
return list;
} @GetMapping("/delete/{id}")
public String remove(@PathVariable(name="id") String id) {
blogRepository.deleteById(id);
return "success";
}
}
5.打开下载好的Elasticsearch(6.2.4)内的elasticsearch.bat文件,等待一会儿直到启动完成。

6.启动SpringBoot应用并简单的测试
添加一条数据:

查询所有数据:

SpringBoot(2.0.4.RELEASE)+Elasticsearch(6.2.4)+Gradle简单整合的更多相关文章
- springBoot系列教程01:elasticsearch的集成及使用
1.首先安装elasticsearch 集群环境,参考 http://www.cnblogs.com/xiaochangwei/p/8033773.html 注意:由于我的代码采用的是springbo ...
- 001-快速搭建Spring web应用【springboot 2.0.4】-gradle、springboot的启动过程分析、gradle多模块构建
一.概述 学习<精通Spring MVC4>书籍笔记 二.笔记 1.快速构建Spring starter web项目几种方式 1>使用Spring Tool Suite生成Start ...
- SpringBoot(1.5.6.RELEASE)源码解析
转自 https://www.cnblogs.com/dylan-java/p/7450914.html 启动SpringBoot,需要在入口函数所在的类上添加@SpringBootApplicati ...
- 搭建 springboot 2.0 mybatis 读写分离 配置区分不同环境
最近公司打算使用springboot2.0, springboot支持HTTP/2,所以提前先搭建一下环境.网上很多都在springboot1.5实现的,所以还是有些差异的.接下来咱们一块看一下. 文 ...
- SpringBoot 2.0 pom.xml 配置(热启动)
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven ...
- springboot 2.0 mariadb hikari-cp连接池
直到今天 2018年9月29日 10:00:38 ,hikari-cp 在maven 官方仓库最新版本为2.6 SpringBoot 2.0.5 控制台输出,默认的是 2.7.9 spring-boo ...
- SpringBoot入门(0) HelloWorld的实现与原理分析
SpringBoot(0) HelloWorld的实现与原理分析 一.环境准备 1.1 环境约束 –jdk1.8:Spring Boot 推荐jdk1.7及以上:java version “1.8.0 ...
- IntelliJ IDEA 2017版 spring-boot 2.0.3 部署war包项目和jar包项目
1.建立项目 Java Controller package com.springboot.jsp.controller; import org.springframework.stereotype. ...
- SpringBoot2.0.2 不使用parent作为maven单继承方式操作 : org.springframework.boot : spring-boot-dependencies : 2.0.2.RELEASE
1.pom配置方式 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...
随机推荐
- css单位分析、颜色设置与调色板
CSS单位分析 px:单位代表像素,1px代表一个像素点. %:设置子元素为父容器的占比. em:代表该元素中一个字体所占字符,常用在文字首行缩进.其具有继承性. rem:始终代表html中的字符所在 ...
- python 小练习 5
Py从小喜欢奇特的东西,而且天生对数字特别敏感,一次偶然的机会,他发现了一个有趣的四位数2992, 这个数,它的十进制数表示,其四位数字之和为2+9+9+2=22,它的十六进制数BB0,其四位数字之和 ...
- 70. Climbing Stairs爬楼梯
网址:https://leetcode.com/problems/climbing-stairs/ 其实就是斐波那契数列,没什么好说的. 注意使用3个变量,而不是数组,可以节约空间. class So ...
- 基本数据类型dict
1. 字典 dict 用{}来表示 键值对数据 {key:value} 唯一性 键 都必须是可哈希的 不可变的数据类型就可以当做字典中的键 可哈希不可变的数据类型:int str tuple bool ...
- 基数排序模板[luogu 1177]
#include<bits/stdc++.h> #define LL long long using namespace std; ,bas=; ]; LL idx(LL k,LL w) ...
- Linux -- 基于zookeeper的java api(二)
Linux -- 基于zookeeper的java api(二) 写一个关于基于集群的zookeeper的自定义实现HA 基于客户端和监控器:使用监控的方法查看每个注册过的节点的状态来做出操作. Wa ...
- ORA-12537:TNS:connectionclosed错误处理过程
1.ORA-12537:TNS:connectionclosed错误处理过程 检查监听正常,oracle服务也是正常启动的,但是登录不进去. 2.解决方案 1. cd $ORACLE_HOME/bin ...
- HashSet和ArrayList有什么区别
hashSet存储的是无序,不可重复,无索引 ArrayList存储的是有序,可重复,有索引
- Linux查看操作系统版本命令
有时候比如在决定下载软件版本的时候,我们需要确定当前系统的位数和发行版版本. 命令 作用 适用说明 uname -a 显示Linux内核版本和位数 通用,推荐 cat /proc/version 显示 ...
- vp uml uninstall
1◆ vp uml uninstall D:\devsoft\ultimate\idea\plugins\sdeIJ D:\devsoft\ultimate\idea\bin\sde ...