티스토리 뷰
관리자 페이지 구현 중, Order의 Service와 Dao 구현 후, 인터페이스 추출을 했더니 실행 에러가 발생했다.
당연히 되는 건줄 알고 테스트도 안 하고 push했는데… 뭐가 문제인지 몰라서 해매다, 추출 이전으로 원상복구 시켰더니 정상작동했다.
WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderController': Unsatisfied dependency expressed through field 'orderService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderService' defined in file [/Users/jiwoo/Desktop/jangbogo-admin/target/admin-1.0.0-BUILD-SNAPSHOT/WEB-INF/classes/com/jangbogo/admin/service/OrderService 2.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.jangbogo.admin.service.OrderService]: Specified class is an interface
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'orderController':
Unsatisfied dependency expressed through field 'orderService';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'orderService' defined in file [/Users/jiwoo/Desktop/jangbogo-admin/target/admin-1.0.0-BUILD-SNAPSHOT/WEB-INF/classes/com/jangbogo/admin/service/OrderService 2.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException:
**Failed to instantiate [com.jangbogo.admin.service.OrderService]: Specified class is an interface**
문제 🎨
우리는 스프링 MVC 패턴을 구현하면서 특정 기능에 대한 Service, Dao 파일을 생성합니다.
해당 파일들에 C.R.U.D에 관한 메서드를 정의하죠. 그리고 위 파일들에 대해 인터페이스(Interface)를 추출합니다.
IntelliJ의 기능을 사용하여 Service, Dao의 인터페이스를 추출하고, 기존 클래스의 이름을 xxxServiceImpl 또는 xxxDaoImpl로 이름을 변경(refacgtor)했습니다.
그런데, 이후 톰캣 서버를 실행하자 ‘에러’가 발생합니다.
해결방안 👨🏻🎨
도저히 해결의 실마리를 찾지 못하고 시간이 지났습니다. 5일 뒤 해결방안을 찾았습니다.
로그에 출력된 에러 메시지 중 일부를 보여드리겠습니다.
Error creating bean with name 'orderService' defined in file
[/Users/jiwoo/Desktop/jangbogo-admin/**target**/
admin-1.0.0-BUILD-SNAPSHOT/WEB-INF/classes/com/jangbogo/admin/
service/**OrderService 2.class**]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.jangbogo.admin.service.OrderService]: Specified class is an interface
target 폴더에 있는 OrderService 2.class 파일을 초기화할 수 없다고 나옵니다.
target 폴더란, 메이븐으로 빌드를 하면 생기는 폴더로, war파일을 저장합니다.
프로젝트의 결과물인 war(jar)파일을 실제 서버에 반영할 때 target폴더에 있는 .war파일을 배포합니다.
커밋 대상이 아닙니다.
target폴더를 확인해보았습니다.

저 말도 안 되는 넘버링이 된 파일들 보이시죠?
톰캣이 저 놈을 참조하고 있었기 때문에 실행이 제대로 안 된 것이었습니다. 해당 파일들을 전부 삭제해줍니다.
다시 톰캣 실행을 시도하면 문제없이 실행되는 것을 확인할 수 있습니다.
아예, target 폴더 삭제 후 maven reload한 다음, 다시 톰캣을 실행하는 방법도 있습니다.
애초에 이런 에러가 왜 생기는 지는 좀 더 연구가 필요할 것 같다.
'트러블 슈팅 🥤' 카테고리의 다른 글
| Refused to apply style from 'http://localhost:8080/css/main.css' because... (0) | 2023.05.09 |
|---|---|
| [공유] [IntelliJ] 인텔리제이 콘솔 한글 출력 깨짐 (0) | 2022.10.31 |
| 🕵️♂️ '컴퓨터가 클래스를 못 찾는다' 시리즈 (0) | 2022.10.25 |
| [에러 창고] Error: Could not find or load main class com.fastcampus.ch2.YoilTeller (0) | 2022.10.18 |
| 에러 모음집 (0) | 2019.12.31 |
댓글
공지사항
