gpt4 book ai didi

java - 当我使用 ContextHierarchy 时,没有类型为 'org.springframework.security.config.annotation.ObjectPostProcessor' 的合格 bean 可用

转载 作者:行者123 更新时间:2023-12-05 07:12:52 25 4
gpt4 key购买 nike

我想在 SpringBootTest 中使用数据库缓存上下文。

当在 ContextHierarchy 中尝试两个 ContextConfiguration 时:

@SpringBootTest(properties = {"spring.main.allow-bean-definition-overriding=true"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextHierarchy({
@ContextConfiguration(classes = {DatabaseTestConfiguration.class}),
@ContextConfiguration(classes = {OverridingTestConfiguration.class}),
})
public class MyTest {
// test methods
}

我得到异常:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor<?>' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:343)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:335)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1123)
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setApplicationContext(WebSecurityConfigurerAdapter.java:374)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:708)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
... 85 more

当我在 ContextHierarchy 中联合 ContextConfiguration 时:

@SpringBootTest(properties = {"spring.main.allow-bean-definition-overriding=true"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextHierarchy({
@ContextConfiguration(classes = {DatabaseTestConfiguration.class, OverridingTestConfiguration.class}),
})
public class MyTest {
// test methods
}

具有额外 OverridingTestConfiguration 的上下文缓存。

谁能告诉我这里出了什么问题?

最佳答案

我有一个非常相似的问题,并且在我添加@EnableWebSecurity 注释后得到解决。试试看

关于java - 当我使用 ContextHierarchy 时,没有类型为 'org.springframework.security.config.annotation.ObjectPostProcessor<?>' 的合格 bean 可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60303286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com