记录一次掉坑过程
程序员文章站
2022-04-28 11:24:01
...
此次项目我用的是spring boot+mybatis+mysql, 这些都很正常,因为需要调用外部接口,在spring-application.xml里做了些配置,
然后通过@ImportResource实现xml配置的装载,结果项目启动不起来,报错如下:
2018-11-05 09:32:01.830 INFO 22260 --- [ main] com.pst.api.PstV2ApiApplication : Starting PstV2ApiApplication on LAPTOP-NJL0QPBO with PID 22260 (D:\Git\pst-v2-api\target\classes started by chen in D:\Git\pst-v2-api)
2018-11-05 09:32:01.833 INFO 22260 --- [ main] com.pst.api.PstV2ApiApplication : No active profile set, falling back to default profiles: default
2018-11-05 09:32:02.464 WARN 22260 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to register bean definition with name 'httpUtils'
Offending resource: class path resource [spring-application.xml]; nested exception is org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'httpUtils' defined in class path resource [spring-application.xml]: Cannot register bean definition [Generic bean: class [com.pst.api.support.util.http.HttpUtils]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [spring-application.xml]] for bean 'httpUtils': There is already [Generic bean: class [com.pst.api.support.util.http.HttpUtils]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\Git\pst-v2-api\target\classes\com\pst\api\support\util\http\HttpUtils.class]] bound.
2018-11-05 09:32:02.469 INFO 22260 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-05 09:32:02.471 ERROR Disconnected from the target VM, address: '127.0.0.1:56800', transport: 'socket'
22260 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'httpUtils', defined in class path resource [spring-application.xml], could not be registered. A bean with that name has already been defined in file [D:\Git\pst-v2-api\target\classes\com\pst\api\support\util\http\HttpUtils.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
说是名字重复了,简直莫名奇妙,然后就开始各种排查,大概花了一个小时时间,最后在*上找到了答案,
原帖:https://*.com/questions/51953129/facing-issue-with-microservice-using-netflix-zuul-in-springboot
原来springboot 2.1.x 并不支持这种操作,改回到2.0.x,项目正常启动。
希望我的掉坑能给大家一点帮助,特此记录。