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 ...
随机推荐
- spring boot(九)定时任务
在我们的项目开发过程中,经常需要定时任务来帮助我们来做一些内容,springboot默认已经帮我们实行了,只需要添加相应的注解就可以实现 1.pom包配置 pom包里面只需要引入springboot ...
- 4月12 php练习
php中输出 <?php echo'hello'; php中打印多个div <?php for($i=1;$i<=100;$i++) { ?> <div style=&q ...
- token原理详解
概念与使用流程 是计算机术语:令牌,令牌是一种能够控制站点占有媒体的特殊帧,以区别数据帧及其他控制帧.token其实说的更通俗点可以叫暗号,在一些数据传输之前,要先进行暗号的核对,不同的暗号被授权不同 ...
- hdu-6397-容斥
Character Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- 判断input[type=file]上传文件格式
input type="file" 在js中判断文件上传类型 function onSubmit(){ var form1 = document.forms[0]; var fil ...
- Leetcode 1006. 笨阶乘
1006. 笨阶乘 显示英文描述 我的提交返回竞赛 用户通过次数305 用户尝试次数347 通过次数309 提交次数665 题目难度Medium 通常,正整数 n 的阶乘是所有小于或等于 n 的 ...
- maven聚合工程tomcat插件启动没有 Starting ProtocolHandler ["http-bio-8081"]
Starting ProtocolHandler ["http-bio-8081"]无法显示,一般有三个原因: (1)数据库连不上: (2)注册中心连不上(我这里用的是zookee ...
- eclipse安装scala环境
1.安装eclipse插件,依次点击Help->Eclipse Marketplace 2.输入scala,点击go,进行搜索 3,出现了Scala IDE4.7X,点击右下方的Install进 ...
- 关于JAVA的一些知识点
1.java.lang.Runtime.getRuntime().availableProcessors() Returns the number of processors available to ...
- CentOS最小安装无法使用ifconfig命令
问题描述: 1.先解决联网问题,详情查看:http://www.cnblogs.com/zhi-leaf/p/5983470.html. 2.执行net-tools,执行命令 yum install ...