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 ...
随机推荐
- python中for循环的底层实现机制 迭代
在python中,存在2种循环方式:for循环和while循环. while循环的实现很简单, 其本质就是一个条件语句,自定义条件,当条件满足的时候,不断执行while代码块. 但是for循环,究竟是 ...
- leetcode-algorithms-4 Median of Two Sorted Arrays
leetcode-algorithms-4 Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of siz ...
- HDU-6395-矩阵快速幂
Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- vue 关于npm run build 的小问题
vue项目使用npm run build命令进行打包操作,打包之后试运行报错,报错为: 且命令行警告信息为: 解决办法: 找到项目目录下的config文件夹里的index.js文件,将build对象下 ...
- python 小练习 7
有一楼梯共n级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第n级,共有多少种走法? 这其实是fibonacci数列,记走法为f(n),在n-1和n-2时你都可以直接跨上去.因此 f(n) = ...
- 1003. Check If Word Is Valid After Substitutions Medium检查替换后的词是否有效
网址:https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/ 参考:https://leetcode.com ...
- MySQL5.6复制技术(4)-MySQL主从复制过滤参数
复制的过滤主要有2种方式: 在主服务器在把事件从进二制日志中过滤掉,相关的参数是:binlog_do_db和binlog_ignore_db. 在从服务器上把事件从中继日志中过滤掉,相关的参数是re ...
- vue组件生命周期详解
Vue所有的生命周期钩子自动绑定在this上下文到实例中,因此你可以访问数据,对属性和方法进行运算.这意味着你不能使用箭头函数来定义一个生命周期方法.这是因为箭头函数绑定了父上下文,因此this与你期 ...
- python 解析与生成xml
xml.etree.ElementTree模块为xml文件的提取和建立提供了简单有效的API.下文中使用ET来代表xml.etree.ElementTree模块. XML是一种内在的分层的数据形式,展 ...
- [LeetCode] 108. Convert Sorted Array to Binary Search Tree ☆(升序数组转换成一个平衡二叉树)
108. Convert Sorted Array to Binary Search Tree 描述 Given an array where elements are sorted in ascen ...