반응형
[스프링부트] jar, war 내에서 ResourceUtil.getFile() 사용시 FileNotFoundException 발생
//XML 파일의 내용을 가져온다.
XmlMapper xmlMapper = new XmlMapper();
File file = ResourceUtils.getFile(replicationXmlFilePath);
if (!file.exists()) {
throw new Exception("replication.xml is Not File..");
}
List<DBInfo> dbInfoList = xmlMapper.readValue(file, xmlMapper.getTypeFactory().constructCollectionType(List.class, DBInfo.class));
[ERROR](org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler:95) Unexpected error occurred in scheduled task.
java.io.FileNotFoundException: class path resource [replication.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/service/App.war!/WEB-INF/classes!/replication.xml
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:215)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:53)
at com.MonitoringJob.execute(MonitoringJob.java:69)
at com.JobConfiguration.monitoringJob(JobConfiguration.java:210)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Intellij 에서는 Path의 문제가 없었지만 war 내에서는 문제가 생긴다.
//XML 파일의 내용을 가져온다.
XmlMapper xmlMapper = new XmlMapper();
ClassPathResource classPathResource = new ClassPathResource(replicationXmlFilePath);
List<DBInfo> dbInfoList = xmlMapper.readValue(classPathResource.getInputStream(), xmlMapper.getTypeFactory().constructCollectionType(List.class, DBInfo.class));
아래와같이 변경해 주었다.
'JAVA > Java' 카테고리의 다른 글
OAuth2 (0) | 2020.03.18 |
---|---|
정규식 표현(Regular Expression)이란? (0) | 2019.11.29 |
Spring Boot 와 Docker (0) | 2019.10.21 |
Maven Scope 정리 (0) | 2019.10.15 |
Intellij 설정파일 (0) | 2019.09.24 |