Spring boot 豆子';元数据源advisor';,在null中定义,无法注册
我已将Spring Boot版本从2.0.3更新为2.1.1,但我得到了以下信息:Spring boot 豆子';元数据源advisor';,在null中定义,无法注册,spring-boot,Spring Boot,我已将Spring Boot版本从2.0.3更新为2.1.1,但我得到了以下信息: *************************** APPLICATION FAILED TO START *************************** Description: The bean 'metaDataSourceAdvisor', defined in null, could not be registered. A bean with that name has already
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'metaDataSourceAdvisor', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
我得到了一个错误-问题是null中定义的并不是一个很好的指针。我已经看到了,但实际上我更倾向于不允许覆盖不明确的bean
有什么想法吗
日志输出
2019-01-06 07:33:39.282 INFO 29626 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-01-06 07:33:39.282 INFO 29626 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-01-06 07:33:39.912 INFO 29626 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-06 07:33:39.997 INFO 29626 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 80ms. Found 23 repository interfaces.
2019-01-06 07:33:39.999 WARN 29626 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'metaDataSourceAdvisor' defined in null: Cannot register bean definition [Root bean: class [org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'metaDataSourceAdvisor': There is already [Root bean: class [org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2019-01-06 07:33:40.008 INFO 29626 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-06 07:33:40.010 ERROR 29626 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
好的,我自己发现了这个问题:我在我的项目中有两次@EnableGlobalMethodSecurity
:
@配置
@启用Web安全性
@EnableGlobalMethodSecurity(prespenabled=true)//根据Spring Boot 2.1的说明,在接受的答案上展开
默认情况下已禁用Bean重写,以防止意外重写Bean。如果您依赖于重写,则需要将spring.main.allow-bean-definition-overriding设置为true
因此,如果您在代码库中多次使用@EnableGlobalMethodSecurity,并且这些bean是同一组件扫描的一部分,那么此注释将多次尝试创建metaDataSourceAdvisor bean。这将在初始化期间引发异常
这也适用于创建bean的其他自动配置注释。请确保只使用它们的启用注释一次。可以帮助在Gradle或Maven中“清理”和“构建”项目。这不是问题的有效答案。请发布更多详细信息,好吗?我和author面临同样的问题。我使用Gradle,我清理了我的项目,然后再次构建它,它帮助了我。