[Spring Boot] Unable to start embedded Tomcat

김수현·2025년 9월 25일

⚠️ 1. 에러 발생: 또 에러를 만났다,,,


⚠️ 에러 추측: 스프링 시큐리티 로그인/아웃 하던 시점까지 잘 됐었는데

스프링 시큐리티 의존성 추가 -> 회원가입 구현 -> 로그아웃 구현 -> 회원가입/ 로그인/ 로그아웃 실행테스트 까지 끝마쳤으니,
JWT 서비스 구현 과정 ~ OAuth2 서비스 구현 과정에서 문제가 생긴 듯 하다.


⚠️ 2. 에러 원인 파악: 에러 코드 자세히 확인하기

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 에서 의존성을 주입하는 방식을 사용하였는데 미숙한 사용으로 인한 문제하고 파악했다.


✅ 3. 에러 해결!!

  • 에러 코드를 보면 JWT토큰 생성 알고리즘에 secretKey 길이가 맞지 않다는 내용이었다. (256비트 이상이어야 함)

📌 해당 내용을 바탕으로 구글링 결과, 랜덤키를 발급해주는 사이트를 발견하여 랜덤키를 발급받아 application.yml에 넣어주었다.

✅ 운 좋게 첫 시도에 에러를 해결하여 OAuth2 실행 테스트에 성공했다!!




출처: https://gotoendiamwin.tistory.com/9

profile
n년째 초보개발자

0개의 댓글