定义为 null 的 bean 'metaDataSourceAdvisor' 无法注册 [英] The bean 'metaDataSourceAdvisor', defined in null, could not be registered

查看:27
本文介绍了定义为 null 的 bean 'metaDataSourceAdvisor' 无法注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将 Spring Boot 版本从 2.0.3 更新到 2.1.1,但我得到了这个:

I've updated the Spring Boot version from 2.0.3 to 2.1.1 but I'm getting this:

***************************
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

我收到错误消息 - 问题是 defined in null 并不是一个很好的查找指针.我见过 这个问题 但我实际上更愿意继续禁止覆盖不明确的 bean.

I get the error - the problem is that defined in null is not really a good pointer where to look. I've seen this question but I'd actually prefer to keep disallowing overriding ambiguous beans.

有什么想法吗?

日志输出

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:

Okay, I found the issue myself: I had @EnableGlobalMethodSecurity twice in my project:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) // <--
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
}

@SpringBootApplication
@EnableJpaRepositories(basePackages = {"mz.server.spring.repository"})
@EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true) // <--
@EntityScan(basePackages = "mz.server.hibernate.model")
@EnableTransactionManagement
@EnableScheduling
public class Application {
}

所以我想说这是一个不错的 Spring Boot 新功能.

So that's a nice new Spring Boot feature I'd say.

如果您看到此类错误,请注意不需要的重复注释.

Just watch out for unwanted duplicate annotations if you see this kind of error.

这篇关于定义为 null 的 bean 'metaDataSourceAdvisor' 无法注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆