资料查找说明
田守枝java技术博客:http://www.tianshouzhi.com/api/tutorials/springboot/101
fantasic_van的博客:https://blog.csdn.net/fantasic_van/article/details/79309665
天涯泪小武的博客:https://blog.csdn.net/tianyaleixiaowu/article/details/72833940
Spring Data Elasticsearch:
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#project
小盒子的博客:https://blog.csdn.net/m0_37044606/article/details/79793125
官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
1 项目搭建
1.1 新建spring boot的elasticsearch项目
用STS新建,勾选JDBC、Mybatis、Web、Mysql、nosql里的elasticsearch选项,等待创建完成即可。
创建完成后,查看项目架构如下:
1.2 热加载(部署)
在SpringBoot1.3.1之后,devtools已经正式发布到Maven中央仓库,只要进行如下配置即可:
1.3 配置yml文件
2 测试
测试的工程目录如下:
2.1 写一个自己的Controller测试
@RestController
public class TestController {
@RequestMapping("/hello")
public String test(){
return "hello world!";
}
}
2.2 运行spring-boot的入口文件EsDemoApplication.java
出现问题如下:
Description:
Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
PS:启用springboot的自动配置,但是又没找到properties中spring.datasource.url属性。
问题解决:http://www.fuzhicode.com/blog/article/104.html
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class EsDemoApplication {
public static void main(String[] args) {
SpringApplication.run(EsDemoApplication.class, args);
}
}
启动成功截图:
2.3 浏览器访问