我们正在升级到SpringBoot 2.1.x和Spring Security 5.1.x。我们有自己的SecurityConfig,它覆盖了org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.中的springSecurityFilterChain bean我已经将该属性添加到applications.property文件中,并将其设置为true,但它仍然不允许覆盖。
我们的班级:
@EnableWebSecurity
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public FilterChainProxy springSecurityFilterChain() throws Exception {
blahblahblah
}
} 和Spring类:
package org.springframework.security.config.annotation.web.configuration;
@Configuration
public class WebSecurityConfiguration implements ImportAware, BeanClassLoaderAware {
@Bean(
name = {"springSecurityFilterChain"}
)
public Filter springSecurityFilterChain() throws Exception {
blahblah
}
}错误:
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文件吗?
发布于 2020-12-24 04:34:58
这里也有同样的问题。这个问题的解决方案是什么?我有过
@Bean
@Primary
public ScheduledLockConfiguration taskScheduler(LockProvider lockProvider) {
}但是它似乎不会被调用,因为第三方库中存在另一个同名的bean。
https://stackoverflow.com/questions/60382215
复制相似问题