
스프링 시큐리티 의존성 추가 -> 회원가입 구현 -> 로그아웃 구현 -> 회원가입/ 로그인/ 로그아웃 실행테스트 까지 끝마쳤으니,
JWT 서비스 구현 과정 ~ OAuth2 서비스 구현 과정에서 문제가 생긴 듯 하다.
2025-09-25T20:58:05.545+09:00 ERROR 6512 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webOAuthSecurityConfig' defined in file [C:\inf_study\spring-blog\build\classes\java\main\springboot_developer\spring_blog\config\WebOAuthSecurityConfig.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'tokenProvider' defined in file [C:\inf_study\spring-blog\build\classes\java\main\springboot_developer\spring_blog\config\jwt\TokenProvider.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'jwtSigningKey' defined in class path resource [springboot_developer/spring_blog/config/jwt/JwtConfig.class]: Failed to instantiate [javax.crypto.SecretKey]: Factory method 'jwtSigningKey' threw exception with message: The specified key byte array is 120 bits which is not secure enough for any JWT HMAC-SHA algorithm. The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size). Consider using the io.jsonwebtoken.security.Keys#secretKeyFor(SignatureAlgorithm) method to create a key guaranteed to be secure enough for your preferred HMAC-SHA algorithm. See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.
[javax.crypto.SecretKey]: Factory method 'jwtSigningKey' threw exception with message:
The specified key byte array is 120 bits which is not secure enough for any JWT HMAC-SHA algorithm.
The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size).
Consider using the io.jsonwebtoken.security.Keys#secretKeyFor(SignatureAlgorithm) method to create a key guaranteed to be secure enough for your preferred HMAC-SHA algorithm.
첫번째 추측한 원인은 예제에서는 사용하지 않던 jwtSigningKey 을 추가한 부분이라고 생각했다.
스프링 시큐리티의 버전이 올라가면서 현재는 deprecation 된 메서드를 정리하는 과정에서 TokenProvider 클래스에 private final SecretKey jwtSigningKey; 필드를 추가하고 JwtConfig 에서 의존성을 주입하는 방식을 사용하였는데 미숙한 사용으로 인한 문제하고 파악했다.
📌 해당 내용을 바탕으로 구글링 결과, 랜덤키를 발급해주는 사이트를 발견하여 랜덤키를 발급받아 application.yml에 넣어주었다.
✅ 운 좋게 첫 시도에 에러를 해결하여 OAuth2 실행 테스트에 성공했다!!