elasticsearch做测试用例的时候报错
来源:7-5 -Elasticsearch 实-文档、资源库、测试用例
Yuuki_L
2018-03-14
报错如上:
相关程序代码
//gradle.build buildscript { ext { springBootVersion = '2.0.0.RELEASE' } // 自定义 Elasticsearch 的版本 //ext['elasticsearch.version'] = '5.2.2' repositories { //mavenCentral() maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { //mavenCentral() maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' } } dependencies { compile('org.springframework.boot:spring-boot-starter-web') // 添加 Spring Data Elasticsearch 的依赖 compile('org.springframework.boot:spring-boot-starter-data-elasticsearch') // 添加 JNA 的依赖 compile('net.java.dev.jna:jna:4.3.0') testCompile('org.springframework.boot:spring-boot-starter-test') }
//repository package com.example.demo.blog.repository.es; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import com.example.demo.blog.domain.EsBlog; /** * EsBlog Repository 接口 * @author lightning * */ public interface EsBlogRepository extends ElasticsearchRepository<EsBlog, String> { Page<EsBlog> findDistinctEsBlogByTitleContainingOrSummaryContainingOrContentContaining (String title,String summary,String content,Pageable pageable); }
//test package com.example.demo.blog.repository.es; import static org.assertj.core.api.Assertions.assertThat; import org.hamcrest.core.Is; import org.junit.Before; 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.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.test.context.junit4.SpringRunner; import com.example.demo.blog.domain.EsBlog; @RunWith(SpringRunner.class) @SpringBootTest public class EsBlogRespositoryTest { @Autowired private EsBlogRepository esBlogRepository; @Before public void initRepositoryData() { esBlogRepository.deleteAll(); esBlogRepository.save(new EsBlog("静夜思","李白","床前看月光,疑是地上霜。抬头望山月,低头思故乡。")); esBlogRepository.save(new EsBlog("静夜思","李白","床前看月光,疑是地上霜。抬头望山月,低头思故乡。")); esBlogRepository.save(new EsBlog("静夜思","李白","床前看月光,疑是地上霜。抬头望山月,低头思故乡。")); } @Test public void testfindDistinctEsBlogByTitleContainingOrSummaryContainingOrContentContaining() { Pageable pageable=new PageRequest(0, 20); String title="思"; String summary="相思"; String content="相思"; Page<EsBlog> page=esBlogRepository.findDistinctEsBlogByTitleContainingOrSummaryContainingOrContentContaining(title, summary, content, pageable); assertThat(page.getTotalElements()).isEqualTo(1); System.out.println("***********"); for(EsBlog blog:page.getContent()) { System.out.println(blog); } System.out.println("***********"); } }
写回答
2回答
-
Yuuki_L
提问者
2018-03-14
不好意思。还是老问题。复制的时候没注意,还是我之前高版本的 springBootVersion = '2.0.0.RELEASE'
00 -
Yuuki_L
提问者
2018-03-14
然后回到打开的elasticsearch,发现了报错。
elasticsearch下的是2.4.4版本。
012018-03-14
基于Spring Boot技术栈博客系统企业级前后端实战
毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap
1296 学习 · 738 问题
相似问题