Spring Boot-创建名称为 'defaultValidator' 的 bean 时出错
Springboot- Error creating bean with name 'defaultValidator'
我正在创建一个 springboot 程序,在我更改 SQL table 并添加列 skipMerge 之前它一直在工作。
我的实体class:
package com.chansoft.Entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.lang.NonNull;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "files")
@Getter
@Setter
public class FilesEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "fileID")
private Long fileID;
@Column(name = "uploaded", columnDefinition = "tinyint(1)")
@NonNull
private boolean uploaded;
@Column(name = "ocrCompleted", columnDefinition = "tinyint(1)")
@NonNull
private boolean ocrCompleted;
@Column(name = "ocrDownloaded", columnDefinition = "tinyint(1)")
@NonNull
private boolean ocrDownloaded;
@Column(name = "ocrIndexed", columnDefinition = "tinyint(1)")
@NonNull
private boolean ocrIndexed;
@Column(name = "ocrJSONFileName", columnDefinition = "json")
private String ocrJSONFileName;
@Column(name = "fileDirectory", columnDefinition = "varchar(1000)")
private String fileDirectory;
@Column(name = "gcsDirectory", columnDefinition = "varchar(1000)")
private String gcsDirectory;
@Column(name = "isCombined", columnDefinition = "tinyint(1)")
private boolean isCombined;
@Column(name = "skipMerge", columnDefinition = "tinyint(1)")
private boolean skipMerge;
}
我的仓库class:
package com.chansoft.Repositories;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import com.chansoft.Entities.FilesEntity;
@RepositoryRestResource(exported = false)
public interface FilesRepository extends CrudRepository<FilesEntity, Long> {
public List<FilesEntity> findByFileDirectoryIgnoreCase(String FileDirectory);
public List<FilesEntity> findByUploaded(boolean Uploaded);
public List<FilesEntity> findByIsCombinedAndSkipMerge(boolean IsCombined, boolean SkipMerge);
}
MySQLtable:
有人有线索吗?它没有丢失依赖项,因为它之前工作得更早,没有更改 table。我尝试注释掉实体、存储库、服务和控制器中的 skipMerge 部分,但无济于事。
谢谢!
编辑:我得到这个作为我的堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: Receiver class org.hibernate.validator.engine.ConfigurationImpl does not define or inherit an implementation of the resolved method 'abstract javax.validation.ParameterNameProvider getDefaultParameterNameProvider()' of interface javax.validation.Configuration.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=13=](AbstractBeanFactory.java:335) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.chansoft.PdfOcrReaderApplication.main(PdfOcrReaderApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.6.jar:2.6.6]
Caused by: java.lang.AbstractMethodError: Receiver class org.hibernate.validator.engine.ConfigurationImpl does not define or inherit an implementation of the resolved method 'abstract javax.validation.ParameterNameProvider getDefaultParameterNameProvider()' of interface javax.validation.Configuration.
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.configureParameterNameProvider(LocalValidatorFactoryBean.java:327) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:293) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.18.jar:5.3.18]
... 21 common frames omitted
失败与您对实体所做的更改无关。
该异常表明类路径上的 Hibernate Validator 版本与类路径上的验证 API 版本不兼容。 Hibernate Validator 比 API 旧并且没有实现 getDefaultParameterNameProvider
.
您可以通过更改 build.gradle 或 pom.xml 来解决问题。使用 Spring Boot 2.6.6,您应该使用 Hibernate Validator 6.2.3.Final。如果您正在使用 Spring Boot 的依赖管理,您可以在构建脚本中删除该版本,然后它将自动使用 6.2.3.Final。
我正在创建一个 springboot 程序,在我更改 SQL table 并添加列 skipMerge 之前它一直在工作。
我的实体class:
package com.chansoft.Entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.lang.NonNull;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "files")
@Getter
@Setter
public class FilesEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "fileID")
private Long fileID;
@Column(name = "uploaded", columnDefinition = "tinyint(1)")
@NonNull
private boolean uploaded;
@Column(name = "ocrCompleted", columnDefinition = "tinyint(1)")
@NonNull
private boolean ocrCompleted;
@Column(name = "ocrDownloaded", columnDefinition = "tinyint(1)")
@NonNull
private boolean ocrDownloaded;
@Column(name = "ocrIndexed", columnDefinition = "tinyint(1)")
@NonNull
private boolean ocrIndexed;
@Column(name = "ocrJSONFileName", columnDefinition = "json")
private String ocrJSONFileName;
@Column(name = "fileDirectory", columnDefinition = "varchar(1000)")
private String fileDirectory;
@Column(name = "gcsDirectory", columnDefinition = "varchar(1000)")
private String gcsDirectory;
@Column(name = "isCombined", columnDefinition = "tinyint(1)")
private boolean isCombined;
@Column(name = "skipMerge", columnDefinition = "tinyint(1)")
private boolean skipMerge;
}
我的仓库class:
package com.chansoft.Repositories;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import com.chansoft.Entities.FilesEntity;
@RepositoryRestResource(exported = false)
public interface FilesRepository extends CrudRepository<FilesEntity, Long> {
public List<FilesEntity> findByFileDirectoryIgnoreCase(String FileDirectory);
public List<FilesEntity> findByUploaded(boolean Uploaded);
public List<FilesEntity> findByIsCombinedAndSkipMerge(boolean IsCombined, boolean SkipMerge);
}
MySQLtable:
有人有线索吗?它没有丢失依赖项,因为它之前工作得更早,没有更改 table。我尝试注释掉实体、存储库、服务和控制器中的 skipMerge 部分,但无济于事。
谢谢!
编辑:我得到这个作为我的堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: Receiver class org.hibernate.validator.engine.ConfigurationImpl does not define or inherit an implementation of the resolved method 'abstract javax.validation.ParameterNameProvider getDefaultParameterNameProvider()' of interface javax.validation.Configuration.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=13=](AbstractBeanFactory.java:335) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.chansoft.PdfOcrReaderApplication.main(PdfOcrReaderApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.6.6.jar:2.6.6]
Caused by: java.lang.AbstractMethodError: Receiver class org.hibernate.validator.engine.ConfigurationImpl does not define or inherit an implementation of the resolved method 'abstract javax.validation.ParameterNameProvider getDefaultParameterNameProvider()' of interface javax.validation.Configuration.
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.configureParameterNameProvider(LocalValidatorFactoryBean.java:327) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:293) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.18.jar:5.3.18]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.18.jar:5.3.18]
... 21 common frames omitted
失败与您对实体所做的更改无关。
该异常表明类路径上的 Hibernate Validator 版本与类路径上的验证 API 版本不兼容。 Hibernate Validator 比 API 旧并且没有实现 getDefaultParameterNameProvider
.
您可以通过更改 build.gradle 或 pom.xml 来解决问题。使用 Spring Boot 2.6.6,您应该使用 Hibernate Validator 6.2.3.Final。如果您正在使用 Spring Boot 的依赖管理,您可以在构建脚本中删除该版本,然后它将自动使用 6.2.3.Final。