当前位置: 首页 > 知识库问答 >
问题:

无法注册定义为null的bean“Meta DataSourceAdvisor”

陈斌蔚
2023-03-14
***************************
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
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   : 

共有1个答案

钱修雅
2023-03-14

好吧,我自己发现了这个问题:我在项目中有@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开机功能。

 类似资料:
  • 问题内容: 我已经将Spring Boot版本从2.0.3更新到2.1.1,但是我得到了: 我得到了错误-问题是在哪里看并不是一个好的指针。我已经看到了这个问题,但是我实际上更愿意继续禁止覆盖不明确的豆类。 有任何想法吗? 日志输出 问题答案: 好的,我自己发现了这个问题:我在项目中有两次: 和 所以我想说这是一个很好的Spring Boot新功能。 如果您看到这种错误,只需小心不要重复的注释。

  • 我正在做一个简单的博客后端,作为一个个人项目。我这样做是为了尝试获取一些JavaSpring,我对下面的代码有问题(有很多...)。 我得到的错误正是这样的:定义为null的bean“postRepository”无法注册。已在null中定义了具有该名称的bean,并且已禁用重写。 代码本身在最初使用Hibernate时运行良好,我有2个DAO,2个DAOMPLS,并使用服务类中的DAOMPLS调

  • 我正在开发一个使用Log4j(1.2.16)日志记录的Web应用程序。为了避免编辑大量文件,我试图钩住自定义LoggerFactory实现,防止日志伪造。 似乎可以设置配置设置(project使用属性文件方法)指定要使用的记录器工厂。然而,这似乎不起作用。在检查了Log4j的源代码之后,似乎从未真正使用过该属性,即使它是由PropertyConfigurator类读取的。 检查更多的Log4j源代

  • 我是新来的Laravel。我有两种不同的用户类型:老师和学生。教师在网站注册表格中注册账户,但学生注册由windows应用程序提供。所以我必须为这个应用程序提供一个API。默认Laravel认证是足够的教师注册,但我可以使用相同的AuthController API注册?我不需要视图或重定向到网站。

  • 我已经为log4j2编写了一个自定义触发策略,该策略将被回滚。在每小时/天/你的工作时间间隔结束时,按照本SO帖子的建议记录文件。 虽然我遵循基于时间的触发策略约定(命名等),但我无法看到我的策略被实例化和使用。 解决方案由3个java文件和一个maven文件组成,可在github上获得 在这里,您可以从政策本身找到主要内容: log4j2。xml文件: 编辑: 在调试过程中,我了解到在log4j

  • 它抛出一个空指针异常。我尝试将它作为无状态和全状态bean使用,但结果仍然相同。 如有任何帮助,我们将不胜感激。这是在JBOSS AEP6上运行的JAVA EE。