spring-boot - 定义为 null 的 bean 'metaDataSourceAdvisor' 无法注册

标签 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 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不是一个很好的指针在哪里看。我见过this question但我实际上更愿意继续禁止覆盖模棱两可的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在我的项目中两次:

@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 新功能。

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

关于spring-boot - 定义为 null 的 bean 'metaDataSourceAdvisor' 无法注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54059222/

相关文章:

java - Spring boot graphql 在类路径上找不到 graphql 模式文件

java - Spring Boot 应用程序 - 使用参数调用类而不默认运行

java - 控制异常输出格式

java - Spring Boot 应用程序中存在 JNDI 的原因是什么?

java - Spring Boot 将 HTTP 重定向到 HTTPS

java - 依赖项 org.json :json:jar is missing

spring-boot - 为什么 OAuth2UserService 没有在 WebSecurityConfigurerAdapter 下的 Spring Boot 中运行角色授权?

java - 如何更改已在数据库中注册的 id 列类型

Java Spring : How is the return value of @Async method handled?

java - Spring Boot 关闭前的 Kafka 手动确认