首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpringBoot 2.1 spring.main.allow-bean-definition-overriding=true不工作

SpringBoot 2.1 spring.main.allow-bean-definition-overriding=true不工作
EN

Stack Overflow用户
提问于 2020-02-25 02:49:12
回答 1查看 471关注 0票数 1

我们正在升级到SpringBoot 2.1.x和Spring Security 5.1.x。我们有自己的SecurityConfig,它覆盖了org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.中的springSecurityFilterChain bean我已经将该属性添加到applications.property文件中,并将其设置为true,但它仍然不允许覆盖。

我们的班级:

代码语言:javascript
复制
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Bean
public FilterChainProxy springSecurityFilterChain() throws Exception {
    blahblahblah
    }
} 

和Spring类:

代码语言:javascript
复制
package org.springframework.security.config.annotation.web.configuration;

@Configuration
public class WebSecurityConfiguration implements ImportAware, BeanClassLoaderAware {

    @Bean(
    name = {"springSecurityFilterChain"}
    )
    public Filter springSecurityFilterChain() throws Exception {
         blahblah
    }
}

错误:

代码语言:javascript
复制
org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'springSecurityFilterChain' defined in class path resource

我不清楚为什么没有选择将覆盖属性设置为true。我还尝试将我们的bean注释为主bean、@autoconfigureBefore(WebSecurityConfiguration.class)和从注册表中删除不需要的bean(但还没有弄清楚如何成功地做到这一点)。我试图覆盖的bean是否有什么特殊之处可以阻止它?我需要以某种方式提前加载applications.property文件吗?

EN

回答 1

Stack Overflow用户

发布于 2020-12-24 04:34:58

这里也有同样的问题。这个问题的解决方案是什么?我有过

代码语言:javascript
复制
@Bean
@Primary
public ScheduledLockConfiguration taskScheduler(LockProvider lockProvider) {
}

但是它似乎不会被调用,因为第三方库中存在另一个同名的bean。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60382215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档