Spring Boot - Unable to start embedded Tomcat Error / (ERROR 22996) o.s.b.web.embedded.tomcat 해결

YUNU·2023년 5월 3일
0

스프링

목록 보기
4/33
post-thumbnail

🟦 Unable to start embedded Tomcat Error


APPLICATION FAILED TO START


Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1201)

The following method did not exist:

javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

The calling method's class, org.apache.catalina.authenticator.AuthenticatorBase, was loaded from the following location:

jar:file:/C:/Users/yoond/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/9.0.74/5afe5c4cfc8e78c395207d6abcc98666b508ec0c/tomcat-embed-core-9.0.74.jar!/org/apache/catalina/authenticator/AuthenticatorBase.class

The called method's class, javax.servlet.ServletContext, is available from the following locations:

jar:file:/C:/Users/yoond/.gradle/caches/modules-2/files-2.1/com.google.gwt/gwt-user/2.6.0/8237d1bd37127188107388c8724be44a0e9f73ca/gwt-user-2.6.0.jar!/javax/servlet/ServletContext.class
jar:file:/C:/Users/yoond/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/9.0.74/5afe5c4cfc8e78c395207d6abcc98666b508ec0c/tomcat-embed-core-9.0.74.jar!/javax/servlet/ServletContext.class

The called method's class hierarchy was loaded from the following locations:

javax.servlet.ServletContext: file:/C:/Users/yoond/.gradle/caches/modules-2/files-2.1/com.google.gwt/gwt-user/2.6.0/8237d1bd37127188107388c8724be44a0e9f73ca/gwt-user-2.6.0.jar

Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.apache.catalina.authenticator.AuthenticatorBase and javax.servlet.ServletContext


로그인과 회원가입 API를 만들던 중 위와 같은 에러가 발생하였다...

Tomcat과 Servlet 관련 클래스들의 호환성 문제로 인해 에러가 발생한 것으로 보인다.

발생한 Error는 보통 Spring Security와 같은 라이브러리를 사용할 때, 발생하는 문제라 하여, 라이브러리 버전을 호환시키면 해결되지 않을까 하는 생각을 가지고 문제 해결을 진행하였다.

일단 build.gradle을 확인해보았다.

plugins {
	id 'java'
	id 'org.springframework.boot' version '2.7.11'
	id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

	implementation 'org.springframework.boot:spring-boot-starter-security'

	implementation 'org.springframework.boot:spring-boot-starter-validation'

	implementation 'org.springframework.boot:spring-boot-starter-jdbc'

	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-aop'

	implementation 'org.projectlombok:lombok:1.18.22'

	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.security:spring-security-test'

	//lombok
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'com.mysql:mysql-connector-j'
	annotationProcessor 'org.projectlombok:lombok'

	implementation "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
	implementation "org.glassfish.jaxb:jaxb-runtime:2.3.2"

	//jwt
	implementation 'com.auth0:java-jwt:3.18.2'
	
}

tasks.named('test') {
	useJUnitPlatform()
}

사용하지 않는 의존성이 있어 삭제하고 빌드 후 다시 실행하였다.

Table 생성은 되지만 당연하게도 아직 에러는 완전히 해결되지 않았다.

🟦 Error Message

실행 후 Error 메시지는 아래와 같다.

ERROR 22996 --- [           main] o.s.b.web.embedded.tomcat.
TomcatStarter  : Error starting Tomcat context. 
Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'securityConfig' defined in file [C:\...SecurityConfig.class]
: Unsatisfied dependency expressed through constructor parameter 3; nested exception is org.springframework.beans.factory.BeanCreationException
:Error creating bean with name 'jwtServiceImpl'
: Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException
: Could not resolve placeholder 'jwt.secret' in value "${jwt.secret}"

SecurityConfig에서 JwtServiceImpl 빈을 생성할 때, jwt.secret 프로퍼티의 값을 찾을 수 없다는 에러가 발생하였다.

이것은 jwt.secret 프로퍼티 값이 설정되지 않았기 때문이다...


🟦 해결방법

: scretKey값과 유효기간 값 설정해주자.

바보도 이런 바보가 없다.

@Value 애노테이션 이용하여 값을 추가해주었다.

jwt.secret=(your_secret_key)
jwt.access.expiration=(Access Token 만료시간)
jwt.access.header=(Access Token 식별 헤더 이름)

jwt.refresh.expiration=(Refresh Token의 만료시간)
jwt.refresh.header=(Refresh Token 식별 헤더 이름)

🟦 결론

머쓱...

profile
DDeo99

0개의 댓글