正在尝试测试我的WebSecurityAdapterConfig。Spring上课
。。。编译器请求注入filterChainproxy
,但在为springSecurityFilterChain()
创建bean后,它返回通过字段springSecurityFilterChain
代码:
@Configuration
@Conditional(ProdStagingCondition.class)
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityAdapterConfig extends WebSecurityConfigurerAdapter {
........
@Bean(name = "springSecurityFilterChain")
public FilterChainProxy springSecurityFilterChain() throws ServletException, Exception {
final List<SecurityFilterChain> listOfFilterChains = new ArrayList<SecurityFilterChain>();
// listOfFilterChains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/api/login"), new NoSecurityFilter()));
listOfFilterChains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/docs")));
final FilterChainProxy filterChainProxy = new FilterChainProxy(listOfFilterChains);
return filterChainProxy;
}
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebSecurityAdapterConfig.class)
public class WebSecurityAdapterConfigUnitTest {
@Autowired
private FilterChainProxy springSecurityFilterChain;
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp() {
mockMvc = MockMvcBuilders
.webAppContextSetup(context)
.addFilters(springSecurityFilterChain)
.alwaysDo(print())
.apply(springSecurity())
.build();
}
@Test
public void config() throws Exception {
this.mockMvc
.perform(get("/docs"))
.andExpect(status().is3xxRedirection());
}
}
错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.connectar.wallet.config.WebSecurityAdapterConfigUnitTest': Unsatisfied dependency expressed through field 'springSecurityFilterChain'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.web.FilterChainProxy' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1348)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:399)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.web.FilterChainProxy' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1509)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
... 28 more
我从WebSecurityAdapterConfig类中删除了@Conditional(ProdStagingCondition.class)
@Configuration
@Conditional(ProdStagingCondition.class)
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
以下是例外情况: 我的代码: 我评论了setCacheable(true),因为它给出了一个错误。有人能帮忙吗?
无法解决测试Spring Boot应用程序的问题: 主控制器: 应用程序属性:
大家好,每个人都是spring的新手,正在尝试为CRUD创建一个简单的应用程序,但是我得到了下面的错误。我正在使用STS 创建名为“Client ServiceImpli”的bean时出错:通过字段“Client Repository”表示的不满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“clie
错误:-->org.springframework.beans.factory.unsatisfieddependencyexception:创建名为“home controller”的bean时出错:通过字段“user tokenservice”表示的不满足的依赖项;嵌套异常为org.springframework.beans.factory.unsatisfieddependencyexcep
我有以下代码和结构。我得到以下错误,这是很长的错误消息。 创建名称为'departmentController'的bean时出错:通过字段'departmentService'表示的不满意的依赖项;嵌套异常org.springframework.beans.factory.不满意依赖异常: 实体类 存储库接口 服务等级 控制器类 主课 项目结构 完整错误堆栈跟踪: