spring 启动弹性搜索-配置数据源

spring boot elastic search -configure data source

我正在尝试配置 spring data boot sand ES 项目 在我的 pom.xml 中,我有:

@Configuration
 @EnableElasticsearchRepositories(basePackages = "com.yoyo.elastic.repository")
 public class ElasticConfiguration {


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




@Bean
public ElasticsearchOperations elasticsearchTemplate() throws IOException {
    File tmpDir = File.createTempFile("elastic", Long.toString(System.nanoTime()));
    System.out.println("Temp directory: " + tmpDir.getAbsolutePath());

    final Client client = nodeBuilder().local(true).node().client();
    return  new ElasticsearchTemplate(client);
}

}

在我的 pom xml 我有这个部门:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency> 

应该支持驱动程序,但我一直在获取: 说明:

无法确定数据库类型 NONE

的嵌入式数据库驱动程序 class

操作:

如果您需要嵌入式数据库,请将受支持的数据库放在 class 路径中。如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有配置文件处于活动状态)。

我在尝试 运行 使用 Spring Boot 和 ElasticSearch 进行一些练习时遇到了同样的问题。

现在我发现如果你有

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

spring-boot-starter-data-elasticsearch 一起,不要添加额外的配置 类(您将在其中配置数据源)spring 启动会报错。

其他解决方案是将数据源 属性 添加到 application.properties 并配置独立数据库(如 H2)