[tomcat] class path resource [...] cannot be resolved to URL because it does not exist

rin·2020년 5월 23일
0
post-thumbnail

해당 경로를 찾을 수 없다는 에러
myBatis를 이용한 Spring Web Project를 진행하는 과정에서 맞닿뜨린 에러이다.

Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:/mappers/*.xml]: class path resource [mappers/] cannot be resolved to URL because it does not exist

테스트 코드에서는 classpathsrc/main/resources를 가리키기 때문에 문제가 되지 않았지만 tomcat을 이용하여 artifact를 배포할 때는 classpathWEB-INF/classes를 가리키게 된다.

웹 프로젝트가 war 파일로 말리면서 src/main/resources하위의 모든 소스가 WEB-INF/classes파일로 자동으로 복제되기 때문에 위와같은 변화가 문제가 없어야하지만, (이유는 모르겠지만 🤔) 이 과정이 일어나지 않아서 경로에 원하는 데이터가 존재하지 않는다고 하는 것이다.

따라서 다음처럼 수동으로 WEB-INF/classes하위로 xml 파일들을 모두 복제해두면 문제가 해결된다. (src/main/resources 하위 xml 파일들도 테스트 코드에서 사용하니 그대로둔다.)

profile
🌱 😈💻 🌱

0개의 댓글