이것저것 해보기🌼
springSecurityFilterChain cannot be null 에러 해결방법 본문
에러 로그
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
java.lang.IllegalStateException: springSecurityFilterChain cannot be null. Ensure a Bean with the name springSecurityFilterChain implementing Filter is present or inject the Filter to be used.
at org.springframework.util.Assert.state(Assert.java:97)
at org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurer.beforeMockMvcCreated(SecurityMockMvcConfigurer.java:76)
at org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:176)
at com.figstudy.web.BooksApiControllerTest.setup(BooksApiControllerTest.java:52)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
에러 위치
@BeforeEach
public void setup() {
mvc = MockMvcBuilders
.webAppContextSetup(context)
.apply(springSecurity())
.build();
}
위 코드에서 build() 를 할때 springSecurityChain이 null이라서 에러가 발생한다.
참고 : https://sbs1621.tistory.com/54
https://docs.spring.io/spring-security/site/docs/5.0.x/reference/html/test-mockmvc.html