尝试WebSecurityAdapterConfig.class
在spring测试我的…编译器请求该注入,filterChainproxy
但是在为其创建bean之后springSecurityFilterChain()
返回通过字段表示的不满意的依赖关系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
我@Conditional(ProdStagingCondition.class)
从WebSecurityAdapterConfig类中删除 了
@Configuration
@Conditional(ProdStagingCondition.class)
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
正在尝试测试我的。。。编译器请求注入,但在为创建bean后,它返回通过字段 代码: 错误:
错误:-->org.springframework.beans.factory.unsatisfieddependencyexception:创建名为“home controller”的bean时出错:通过字段“user tokenservice”表示的不满足的依赖项;嵌套异常为org.springframework.beans.factory.unsatisfieddependencyexcep
无法解决测试Spring Boot应用程序的问题: 主控制器: 应用程序属性:
大家好,每个人都是spring的新手,正在尝试为CRUD创建一个简单的应用程序,但是我得到了下面的错误。我正在使用STS 创建名为“Client ServiceImpli”的bean时出错:通过字段“Client Repository”表示的不满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“clie
以下是例外情况: 我的代码: 我评论了setCacheable(true),因为它给出了一个错误。有人能帮忙吗?
我使用的是SpringV1。4.0.释放我得到一个异常“org.springframework.beans.factory.unsatifiedpendencyException:创建名为“trackiHuntServiceImpl”的bean时出错:通过字段“deviceService”表示的未满足的依赖关系”。其方案是多模块的。 我列出了主要的课程代码:
创建名称为clienteRestController的bean时出错:通过字段clientService表示的不满意的依赖项。 创建名称为'clientServiceImpl'的bean时出错:通过字段'client道'表示的不满意的依赖项。 创建名称为ICliente道的bean时出错:初始化方法调用失败。 嵌套异常java.lang.IllegalArgumentExcishop:不是托管类型