프로젝트 설정을 xml로 하고 있었는데 spring security + jwt 토큰을 적용하면서 java 방식으로 변경하였다.
설정 파일을 모두 변경하고 실행했는데 오류가 발생했다. ㅎㅅㅎ;;🚨
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: 'class path resource [query/*.xml]'; nested exception is java.io.FileNotFoundException: class path resource [query/*.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
RootConfig에 경로를 잘못입력했다는 건 알겠는데
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
sqlSessionFactory.setDataSource(dataSource());
sqlSessionFactory.setConfigLocation(new PathMatchingResourcePatternResolver().getResource("classpath:config/mybatis-config.xml"));
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResource("classpath:query/*.xml"));
return (SqlSessionFactory) sqlSessionFactory.getObject();
}
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResource("classpath:query/*.xml"));
경로를 맞게 입력했는데도 계속 오류가 났다. 이틀 날림 ㅎㅎ
어이없게도 문제는 sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResource("classpath:query/*.xml"));
getResource가 아니라 getResources를 사용해야 한다는 것~~!!!
getResource() 메서드는 하나의 파일 또는 리소스를 가져올 때 사용하고, getResources() 메서드는 여러 개의 파일 또는 리소스를 가져올 때 사용한다.
나는 여러개의 파일을 가져오려고 했으므로 getResources를 사용해야했다.
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:query/*.xml"));
변경하니까 오류 해결됨
좋은 경험이었다...... 아무리 검색해도 안 돼서 답답했는데 어떻게든 해결돼서 정말 다행이야....🥲