jUnit에러 -Failed to load ApplicationContext

국물빌런·2020년 3월 3일
0

jUnit테스트로 트랜잭션을 실습 하려고 했더니 다시 에러가 나를 붙잡는다.
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hikariConfig' defined in URL [file:src/main/webapp/WEB-INF/spring/root-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.NoClassDefFoundError: Unable to find Log4j2 as default logging library. Please provide a logging library and configure a valid spyLogDelegator name in the properties file.
at
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.NoClassDefFoundError: Unable to find Log4j2 as default logging library. Please provide a logging library and configure a valid spyLogDelegator name in the properties file.

일단 대충 필요없어 보이는 에러는 자른 형태다.
자..에러를 살펴보니 일단 hikariConfig 객체가 프로퍼티로서 할당될 수 없다고 하네..저넘은 jdbc연결할 때 관련된 녀석이니 일단 JDBC테스트 소스를 들고와서 해봤다.
소스를 가져오는 순간 컴파일 에러가 났다.
아..mysql 커넥터를 안받았다..
maven에서 mysql connector를 받고 다시 확인해보니 에러가 안없어진다. 에러를 자세히 확인해 보니 jre버전이 1.7이상을 쓰라고 한다. 음?난 jdk1.8인데..?
pom.xml확인 해보니 메이븐 컴파일러가 1.6으로 되어있었음.

1.8로 한후 메이븐 업데이트하니 컴파일이 되었다.
결과는 테스트 성공!
그럼 일단 JDBC 접속은 됫고..
DataSource테스트를 해보자.
일단 소스를 가져오니 컴파일은 된다. 근데 위와 같은 에러가 발생함.
HicariConfig가 생성될 수 없는 이유가 DataSource가 안되서 그렇단다.후..다시 에러를 찬찬히 읽어보자..
java.lang.NoClassDefFoundError: Unable to find Log4j2 as default logging library. Please provide a logging library and configure a valid spyLogDelegator name in the properties file.
해당 에러가 의미가 있어보인다.
log4j2에 기본 로깅 라이브러리를 찾을 수 없단다.
pom.xml에 log4j-code와 log4j-api를 추가해 봤으나 안된다.
그래 그 문제가 아니겠지.. 해당 에러 메시지로 인터넷 검색을 해보니
log4jdbc.log4j2.properties 파일을 확인해 보라고 한다.
아..없네..ㅎㅎ
위 파일은 log4jdbc로 sql을 디버깅 할때 드라이버 클래스를 정의해 주는 파일이다. 그냥 log4jdbc쓸때는 있어야 한다고 보면 된다.
쓸때 없는걸로 시간을 허비했지만 의존성에 대해 또 하나 알았다.
저 파일을 기존 프로젝트에서 복사하여 넣어주었더니 잘 된다.
뭐 하나 배웠긴 한데 스프링 부트에서도 의미가 잇는 지식일지 모르겠다.요즘은 그냥 스프링 건너뛰고 스프링부트만 할까 라는 생각도 든다.

profile
국물을 달라

0개의 댓글