报错信息:
2019-07-23 11:29:09.457 INFO 39488 --- [ restartedMain] com.xxx.xxx.xxxApplication : Starting xxxApplication on IT-LAPTOP01 with PID 39488 (started by 50015573 in D:\Devops Project\xxx)
2019-07-23 11:29:09.488 INFO 39488 --- [ restartedMain] com.xxx.xxx.xxxApplication : No active profile set, falling back to default profiles: default
2019-07-23 11:29:09.570 INFO 39488 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-07-23 11:29:09.570 INFO 39488 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-07-23 11:29:11.353 WARN 39488 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'statFilter' defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidFilterConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration; factoryMethodName=statFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidFilterConfiguration.class]] for bean 'statFilter': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=druidConfiguration; factoryMethodName=statFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/xxx/xxx/config/DruidConfiguration.class]] bound.
2019-07-23 11:29:11.366 INFO 39488 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-23 11:29:11.369 ERROR 39488 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'statFilter', defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidFilterConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/xxx/xxx/config/DruidConfiguration.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 0
解决方案:
从报错信息里面分析提示是could not be registered. A bean with that name has already been defined in class path resource [com/xxx/xxx/config/DruidConfiguration.class] and overriding is disabled,表示DruidConfiguration存在两个bean加载发生冲突了。
建议把用Druid的DruidFilterConfiguration.class加载排除掉即可,在启动文件里面加上@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,DruidDataSourceAutoConfigure.class}),DruidConfiguration的jar文件的@Configuration注解保留。不建议在application.properties配置文件中加spring.main.allow-bean-definition-overriding=true,这样子可能会引发跟多报错,有兴趣的小伙可以试试。