提取你的报错关键字进行搜索,看是否有对应的。以下仅为本人遇到的问题及解决办法。
报错一、
2024-08-28 16:21:28.294 ERROR [main] org.springframework.boot.SpringApplication.reportFailure: Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'qwsdApi': Unsatisfied dependency expressed through field 'esService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'esService' defined in.xxxx.xxxx.service.EsService defined in @EnableElasticsearchRepositories declared on ElasticsearchRepositoriesRegistrar.EnableElasticsearchRepositoriesConfiguration: Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration$RestClientConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchRestHighLevelClient' defined in class path resource [org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations$RestHighLevelClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchRestHighLevelClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/xcontent/DeprecationHandler
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPos
原因
导入es的maven依赖包与es版本不兼容
情景描述
springboot版本为:2.6.13,ES版本为7.16.2,maven参考网络仅引入以下两个依赖,报错。
<!--引入es-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.16.2</version>
</dependency>
解决办法
查看es与springboot版本是否合适,然后展开项目树External Libraries查看,是否存在低版本es依赖,经过查看发现存在7.15.2的es依赖。重新引入以下maven依赖,clean后rebuild项目,启动不报错。
Spring Boot | Spring Data Elasticsearch | Elasticsearch |
---|---|---|
2.4.x | 4.1.x | 7.9.x |
2.5.x | 4.2.x | 7.12.x |
2.6.x | 4.3.x | 7.15.x |
2.7.x | 4.4.x | 7.17.x |
<!--引入es-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<!--你的es什么版本,记得修改为什么版本-->
<version>7.16.2</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<!--你的es什么版本,记得修改为什么版本-->
<version>7.16.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
报错二、
java: 无法访问org.springframework.data.elasticsearch.repository.ElasticsearchRepository
错误的类文件: /D:/maven/repository/org/springframework/data/spring-data-elasticsearch/5.3.3/spring-data-elasticsearch-5.3.3.jar!/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.class
类文件具有错误的版本 61.0, 应为 52.0
原因
使用的JDK版本与相关依赖包冲突,可以升级你的JDK版本
情景描述
由于度娘的错误引导,本人引入了更高级的Spring Data Elasticsearch的依赖包,导致编译时报错
解决办法
一、降级依赖包(本人使用方法)
二、升级jdk版本,使用jdk8以上开发包
报错三、
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2024-08-29 08:20:04.236 ERROR [main] org.springframework.boot.SpringApplication.reportFailure: Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rdmsApi': Unsatisfied dependency expressed through field 'esRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'esRepository' defined in com.dytg.materialapi.service.EsRepository defined in @EnableElasticsearchRepositories declared on ElasticsearchRepositoriesRegistrar.EnableElasticsearchRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.dytg.materialapi.service.EsRepository.findEsStandardsByFlagAndTa_noAndSign(java.lang.String,java.lang.String,java.lang.String); Reason: No property 'no' found for type 'String' Traversed path: EsStandard.ta.; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property 'no' found for type 'String' Traversed path: EsStandard.ta. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) at org.springframework.context.support.AbstractApplicationConte
原因
没有匹配到对应的字段,如我这里面就是"no"字段没匹配上
解决办法
java中驼峰命名可对应ES的下划线,但是最好的办法是使用@Field注解,声明哪个字段对应哪个映射
@Field(name="ns_no")
private String nsNo;
报错四、
java.lang.NoSuchFieldError: INDEX_CONTENT_TYPE
原因
springboot版本和spring-data-elasticsearch版本不对应
本人一开始的springboot版本为2.6.13,spring-data-elasticsearch版本为4.3.9,理论上对于springboot2.6.13该spring-data-elasticsearch是对的
解决办法:
注意确保以下配置版本一致:
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.7.14</spring-boot.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.7.14-SNAPSHOT</version>
<scope>test</scope>
</dependency>
一、升级springboot(本人采用),将springboot更改为2.7.14,重新构建后该包版本为:4.4.14
二、更改spring-data-elasticsearch版本