启动SpringBoot报错:The bean ‘beanNameViewResolver‘ 无法注册

文章目录

    • 问题描述
    • 报错原因
    • 解决方法

问题描述

在引入 easypoi 的相关依赖之后,无法启动 SpringBootApplication 服务。

easypoi 依赖:

<dependency>
    <groupId>cn.afterturngroupId>
    <artifactId>easypoi-spring-boot-starterartifactId>
    <version>${easypoi.version}version>
dependency>

启动SpringBootApplication报错,报错信息如下:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-24 22:58:25.213 ERROR 8208 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'beanNameViewResolver', defined in class path resource [cn/afterturn/easypoi/configuration/EasyPoiAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true


Process finished with exit code 1

报错原因

这是因为在 easypoi 的依赖中,有一个注册名称为 beanNameViewResolver 的 Bean 的名称与 SpringBoot 中的一个 Bean 的名称相同,发生了 Bean 名称注册冲突。

easypoi 的 beanNameViewResolver
启动SpringBoot报错:The bean ‘beanNameViewResolver‘ 无法注册_第1张图片
SpringBoot 的 beanNameViewResolver
启动SpringBoot报错:The bean ‘beanNameViewResolver‘ 无法注册_第2张图片

解决方法

配置允许 Bean 的定义覆盖属性为 true

spring:
  main:
    allow-bean-definition-overriding: true

你可能感兴趣的:(Spring,java,spring,spring,boot)