스프링

스프링+ 스프링 시큐리티 테스트에서 contextLoads()만 해도 오류가 나는 이유

rkrkrr0101 2024. 2. 1. 19:42

내가 났던 오류

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration .....
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration'...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filterChain' defined in class path resource...

아무튼 시큐리티관련 빈생성에서 싸그리 문제가 생겨서 테스트에서만 스프링이 안띄워졌음

일단 메인에서 돌아가는데,테스트에서 @SpringBootTest를 사용하면 최대한 단순화해 돌려도 문제가 생겨서

@SpringBootTest
class KotlinApplicationTests {

	@Test
	fun contextLoads() {
	}

}

방향이 대충 시큐리티쪽이라는걸 확정하고도 정확한 원인을 못찾아서 막 3시간동안찾아댕겼음

 

결론은

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: 클라id
            client-secret: 클라시크릿
            redirect-uri: http://localhost:8081/login/oauth2/code/google
            scope:
              - email
              - profile
          naver:
            client-id: 클라id
            client-secret: 클라시크릿
            client-name: Naver
            authorization-grant-type: authorization_code
            redirect-uri: http://localhost:8081/login/oauth2/code/naver
            scope:
              - name
              - email
        provider:
          naver:
            authorization-uri: https://nid.naver.com/oauth2.0/authorize
            token-uri: https://nid.naver.com/oauth2.0/token
            user-info-uri: https://openapi.naver.com/v1/nid/me
            user-name-attribute: response

이거  테스트쪽에 넣는거 까먹어서,oauth2쪽 라이브러리들이 다 뻗은거였음 ㅋㅋ

test/resources/application.yml에 넣자..