每一秒钟的时间都值得铭记

0%

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

问题描述

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

easypoi 依赖:

1
2
3
4
5
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>${easypoi.version}</version>
</dependency>

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 的 beanNameViewResolver
在这里插入图片描述

解决方法

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

1
2
3
spring:
main:
allow-bean-definition-overriding: true
坚持原创技术分享,您的支持将鼓励我继续创作!
-------------这是我的底线^_^-------------