Java Invalid bean definition with name x defined in class path r
問(wèn)題描述:
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'beanNameViewResolver' defined in class path resource [cn/afterturn/easypoi/configuration/EasyPoiAutoConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=cn.afterturn.easypoi.configuration.EasyPoiAutoConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [cn/afterturn/easypoi/configuration/EasyPoiAutoConfiguration.class]] for bean 'beanNameViewResolver': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] bound.
問(wèn)題分析:
1、SpringBoot 集成EasyPoi,在啟動(dòng)初始化容器時(shí)發(fā)現(xiàn)有同名的bean,導(dǎo)致報(bào)錯(cuò)。
解決辦法:
在application.yml配置spring.main.allow-bean-definition-overriding設(shè)置為true,自動(dòng)覆蓋同名的bean。
?