개발에 AtoZ까지

[에러] Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 39; 예기치 않은 파일의 끝입니다. 본문

백엔드/Spring

[에러] Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 39; 예기치 않은 파일의 끝입니다.

AtoZ 개발자 2021. 5. 26. 20:04
반응형

1. 현상

스프링부트 실행 시 아래와 같이 특정 Bean을 못 만들었다면서 서버가 정상적으로 구동되지 않는 에러가 발생했다.

2021-05-26 00:43:24 ERROR org.springframework.boot.SpringApplication[reportFailure:871] - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'schedulerConfig': Unsatisfied dependency expressed through field 'schedulerService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'schedulerServiceImpl': Unsatisfied dependency expressed through field 'schedulerRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'schedulerRepository' defined in file [C:\Users\Mr.K\Desktop\KSH\Programing\Project\ToyProject\Todo-App\Todo-server\bin\main\com\todo\app\mvc\repository\SchedulerRepository.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/todo/app/config/MybatisConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\Mr.K\Desktop\KSH\Programing\Project\ToyProject\Todo-App\Todo-server\bin\main\mapper\.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 39; 예기치 않은 파일의 끝입니다.
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1413)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
	at com.todo.app.TodoServerApplication.main(TodoServerApplication.java:12)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'schedulerServiceImpl': Unsatisfied dependency expressed through field 'schedulerRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'schedulerRepository' defined in file [C:\Users\Mr.K\Desktop\KSH\Programing\Project\ToyProject\Todo-App\Todo-server\bin\main\com\todo\app\mvc\repository\SchedulerRepository.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/todo/app/config/MybatisConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\Mr.K\Desktop\KSH\Programing\Project\ToyProject\Todo-App\Todo-server\bin\main\mapper\.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 39; 예기치 않은 파일의 끝입니다.

 

2. 해결방안

글쓴이는 에러 중 아래와 같은 에러만 보고 의존성주입에 해당되는 BEAN이 실제 객체화가 되지 못하여 발생했을 거라고 생각하고 디버깅을 시도하였다.

Error creating bean with name 'schedulerConfig'

그런데 결과적으로는 다른 이유에 있었다. 원인은  xml 파일을 읽는데 실패했다는 것이였다.

nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\Mr.K\Desktop\KSH\Programing\Project\ToyProject\Todo-App\Todo-server\bin\main\mapper\.xml]';

 

그래서 파일 전체 검색을 해봤는데 작업하면서 실수로 .xml 파일을 만들어 놨었던 것이 문제였다. 하지만... project explorer에는 안보였음...ㅎ  해당 프로젝트 로컬 디렉터리 가서 수동으로 삭제하고 나니깐 정상 구동됐다....ㅎㅎㅎ

 

반응형
Comments