Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

栏目: IT技术 · 发布时间: 5年前

内容简介:在必问里面帮忙回答一个网友的问题:Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2020-07-19 10:47:22.557 ERROR 7412 --- [      main] o.s.b.d.LoggingFailureAnalysisReporter  :

在必问里面帮忙回答一个网友的问题: https://biwen.csdn.net/question/4664

一、问题现象

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2020-07-19 10:47:22.557 ERROR 7412 --- [      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

上面错误已经提示我们在application.ym/application.properties添加如下配置就可以解决。

spring.main.allow-bean-definition-overriding=true

spring.main.allow-bean-definition-overriding设置为true,表示后发现的bean会覆盖之前相同名称的bean。

但是添加这个配置无效,启动仍然提示上面错误。

二、问题分析和原因

1、怀疑 spring没有读取到spring.main.allow-bean-definition-overriding

把这个参数spring.main.allow-bean-definition-overriding放到启动参数里面,然后启动看看:

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

然后启动spring boot报错信息,数据源配置错误:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

这已经说明spring已经正确读取到 spring.main.allow-bean-definition-overriding 。初步怀疑spring没有读取带application.yml 配置。

2、debug数据源配置信息

1)、在启动参数添加spring.datasource.url

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

2)、同时断点debug数据源配置,

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

可以看到数据源配置信息,在启动参数里面 spring.datasource.url 可以读到,但 spring.datasource.usernamespring.datasource.password 没有读取到。

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

明确问题原因:spring无法读取application.yml配置。

由于没有注意springboot启动的提示信息: No active profile set , 但在application.yml已经指明sprin.profiles.active=test. 这就已经说明了spring没有正确读取到application.yml配置。

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

3、分析无法读取application.yml文件的原因

1)springboot编译后默认把application.yml文件是放在target/classes目录下。

查看编译后的目录结构,结果 application.yml是在 BOOT-INF/classes目录下,导致在idea启动时候,spring无法正常读取到application.yml.

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

2)、最后检查maven编译设置,原来是在pom.xm指定了编译路径。

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...

三、问题解决

注释掉这些信息就可以正常启动:

Spring Boot2 记录启动报错The bean ‘beanNameViewResolver‘, defined in class path resource 解...


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

马化腾自述-我的互联网思维

马化腾自述-我的互联网思维

赵黎 / 石油工业出版社 / 2014-8-1 / 35

马化腾自述:我的互联网思维》讲述了些人说移动互联网就是加了“移动”两个字,互联网十几年了,移动互联网应该是个延伸。我的感受是,移动互联网远远不只是一个延伸,甚至是一个颠覆。互联网是一个开放交融、瞬息万变的大生态,企业作为互联网生态里面的物种,需要像自然界的生物一样,各个方面都具有与生态系统汇接、和谐、共生的特性。开放和分享并不是一个宣传口号,也不是一个简单的概念。开放很多时候被看作一种姿态,但是我......一起来看看 《马化腾自述-我的互联网思维》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具