当前位置: 代码迷 >> 综合 >> SpringBoot persistenceExceptionTranslationPostProcessor solution
  详细解决方案

SpringBoot persistenceExceptionTranslationPostProcessor solution

热度:80   发布时间:2023-12-18 12:44:20.0

当自定义的类名是Environment 时,springboot 启动失败。

异常如下:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'persistenceExceptionTranslationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'persistenceExceptionTranslationPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.env.Environment' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

原因:

springframework 自带core.env 包内已有Environment interface, springframework 同类名优先解析内置Environment 接口

解决方案:

将自定义类名替换成别的即可

  相关解决方案