【问题标题】:using springboot with local elastic-search instance not working使用带有本地弹性搜索实例的弹簧启动不起作用
【发布时间】:2023-03-17 19:57:01
【问题描述】:

我想在 spring boot 应用程序中使用 elasticSearch 存储库。 我有一个弹性搜索5.5.2本地运行实例 我已经搜索了一段时间,尝试了多种来源的多种组合,但没有产生有效的解决方案,现在我被 error 困住了:

创建名为“elasticsearchTemplate”的 bean 时出错

我做错了什么?

这是我的

  @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);
            }

        }
}

配置

@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());
    }

}

我的 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")
}

什么是正确的配置方式?一些例子显示了 application.properties 配置,一些没有。 兼容性呢,有的说明只有elasticsearch 2。 * 或更低,有人说 5

真的很混乱:(

非常感谢您的帮助

【问题讨论】:

    标签: java elasticsearch spring-boot spring-data


    【解决方案1】:

    要使用 Elasticsearch 5.x,您需要 Spring Data release Kay(已经发布),它只是 Spring Boot 2(即将发布)的一部分。现在你唯一的选择就是使用最新的 Spring Boot 2 构建并等待稳定版本。

    有些人尝试在 Spring Boot 1.5 中使用 Spring Data Kay,但最终陷入了依赖地狱。即将到来的 Spring Boot 2 可能不值得痛苦。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 2019-05-02
      • 2023-04-04
      • 2022-01-25
      相关资源
      最近更新 更多