简体   繁体   English

使用springboot与本地弹性搜索实例不起作用

[英]using springboot with local elastic-search instance not working

I want to use elasticSearch repository inside a spring boot application . 我想在spring boot应用程序中使用elasticSearch存储库。 I have a local running instance of elastic search 5.5.2 I've search for a while, tried so many combinations of the several sources but nothing yield a working solution , and right now I'm stuck with error : 我有一个在本地运行的弹性搜索实例5.5.2我已经搜索了一段时间,尝试了几种来源的如此多的组合,但没有任何解决方案,现在我陷入了错误

Error creating bean with name 'elasticsearchTemplate' 创建名称为'elasticsearchTemplate'的bean时出错

what am i doing wrong ? 我究竟做错了什么 ?

This is my main class 这是我的

  @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
    public class Application {

        public static void main(String[] args) {

            Logger logger = LoggerFactory.getLogger("chapters.introduction.HelloWorld1");
            try
            {
                SpringApplication.run(Application.class, args);
            }
            catch(Exception e)
            {
                logger.info("caught an exception",e);
            }

        }
}

config class 配置

@Configuration
@EnableElasticsearchRepositories(basePackages = "hello")
@ComponentScan(basePackages = {"hello"})
public class config {

    @Bean
    public NodeBuilder nodeBuilder() {
        return new NodeBuilder();
    }

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() {
        Settings.Builder elasticsearchSettings =
                Settings.settingsBuilder()
                        .put("http.enabled", "false") // 1
                        .put("path.data", "/home/nad/elasticsearch_data") // 2
                        .put("path.home", "/home/nad/Downloads/elasticsearch-5.5.2"); // 3



        return new ElasticsearchTemplate(nodeBuilder()
                .local(true)
                .settings(elasticsearchSettings.build())
                .node()
                .client());
    }

}

my build.gradle file 我的build.gradle文件

group 'FirstWebServer'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'gs-spring-boot'
    version =  '0.1.0'
}

repositories {
    maven { url "http://repo.spring.io/milestone" }
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    // tag::jetty[]
    compile("org.springframework.boot:spring-boot-starter-web") {
        exclude module: "spring-boot-starter-tomcat"
    }
    compile("org.springframework.boot:spring-boot-starter-jetty")
    // end::jetty[]
    // tag::actuator[]
    compile("org.springframework.boot:spring-boot-starter-actuator")
    // end::actuator[]
    //compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '1.2.5.RELEASE'
    compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.0.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.0.0.M6', ext: 'pom'
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile group: 'org.projectlombok', name: 'lombok', version: '1.16.18'

    testCompile("junit:junit")
}

what is the proper way of configuration ? 什么是正确的配置方式? some examples shows application.properties configuration , some dont . 有些示例显示了application.properties配置,有些则没有。 What about compatability , some shows that only elasticsearch 2. * or lower, some said that 5 关于兼容性 ,有的表示仅elasticsearch2 。*或更低,有的表示5

Its really confusing :( 它确实令人困惑:(

Thank you very much for your help 非常感谢您的帮助

To use Elasticsearch 5.x you need Spring Data release Kay (already released), which is only part of Spring Boot 2 (to be released soon). 要使用Elasticsearch 5.x,您需要Spring Data release Kay(已经发布),它只是Spring Boot 2(即将发布)的一部分。 Right now your only option really is to use the latest Spring Boot 2 build and wait for a stable release. 现在,您唯一的选择确实是使用最新的Spring Boot 2构建并等待稳定的发布。

Some people tried using Spring Data Kay with Spring boot 1.5, but ended up in dependency hell. 有些人尝试将Spring Data Kay与Spring Boot 1.5结合使用,但最终陷入了依赖地狱。 Probably not worth the pain with Spring Boot 2 just around the corner. Spring Boot 2指日可待可能带来的痛苦可能不值得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM