gpt4 book ai didi

spring-boot - Elasticsearch和Java Spring Boot:java.lang.NoSuchMethodError:

转载 作者:行者123 更新时间:2023-12-02 22:43:26 24 4
gpt4 key购买 nike

所以我试图让我的Spring Boot Web服务与Elasticsearch对话(我有另一个运行的Java应用程序)

我得到的错误是

DependencyException: Error creating bean with name 'searchController': Unsatisfied dependency expressed through field 'searchService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'searchService': Unsatisfied dependency expressed through field 'searchRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.execute()Lorg/elasticsearch/action/ListenableActionFuture; 2018-10-27 22:18:49.139 INFO 1925 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]



我的依赖(Gradle)是
compile group: 'org.elasticsearch.plugin', name: 'transport-netty4-client', version: '6.4.2'
compile group: 'org.elasticsearch.client', name: 'transport', version: '6.4.2'
compile 'org.elasticsearch:elasticsearch:6.4.2'
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')

我的模特
@org.springframework.data.elasticsearch.annotations.Document(indexName = "burf", type = "pages")
data class Result(@Id val handle: String,
val url: String,
val title: String,
val body: String,
val meta_description: String?) {

}

设定档
@Configuration
@EnableElasticsearchRepositories(basePackages = arrayOf("com.burfdevelopment.skynet.repository\n"))
@ComponentScan(basePackages = arrayOf("com.burfdevelopment.skynet.service"))
class Config {

@Value("\${elasticsearch.home:/usr/local/Cellar/elasticsearch}")
private val elasticsearchHome: String? = null

@Value("\${elasticsearch.cluster.name:skynet}")
private val clusterName: String? = null

@Bean
fun client(): Client {
val settings = Settings.builder()
.put("cluster.name", clusterName).build()

return PreBuiltTransportClient(settings).addTransportAddress(TransportAddress(InetAddress.getByName("192.168.0.100"), 9300))
}

@Bean
fun elasticsearchTemplate(): ElasticsearchOperations {
return ElasticsearchTemplate(client())
}
}

资料库
interface SearchRepository : ElasticsearchRepository<Result, String>  {

fun findByTitle(name: String, pageable: Pageable): Page<Result>
}

有人知道怎么了吗?

最佳答案

您使用的Spring Boot版本使用与Elasticsearch 6.4不兼容的Spring Data Elasticsearch版本。

为了确保使用兼容版本,请从Elasticsearch依赖项中删除该版本,并允许Spring Boot的依赖项管理来控制该版本。

关于spring-boot - Elasticsearch和Java Spring Boot:java.lang.NoSuchMethodError:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53026415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com