티스토리 뷰

728x90
더보기

spring boot에서 mybatis 설정을 properties나 yml의 설정 파일로 직접 설정할 수 도 있고

config-location을 통해서 mybatis config xml 파일의 경로를 지정해줄 수도 있다.

그래서 yml파일에서 config xml을 보도록 경로를 설정해줬는데 오류가 발생했다.

오류 설정파일

# mybatis 설정
mybatis:
  mapper-locations: classpath:mybatis/mapper/*.xml
  config-location: classpath:mybatis/config/*.xml

오류내용

....
Error creating bean with name 'sqlSessionFactory' 
defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.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 java.io.FileNotFoundException: class path resource [mybatis/config/*.xml] cannot be opened because it does not exist
...

 nested exception is java.io.FileNotFoundException: 

class path resource [mybatis/config/*.xml] cannot be opened because it does not exist

 

 

빨간색 부분만 보면 되는데 나는 config-location의 설정도 mapper-locations처럼 * 와일드카드를 사용할 수 있을 줄 알았는데 아니었다.

config-location은 딱 하나만 지정해줘야 한다.

지금 작성하면서 알아낸 건데 config-location 영어에서 단수형

mapper-locations 복수형이었네

 

실제로 org.mybatis.spring.boot.autoconfigure.MybatisProperties.java 파일에 가보면 설정을 확인할 수 있다.

mapper-locations

public void setMapperLocations(String[] mapperLocations) {
  this.mapperLocations = mapperLocations;
}

config-location

public void setConfigLocation(String configLocation) {
  this.configLocation = configLocation;
}

메서드의 매개변수에서도 mapper-locations은 배열로 받고 config-location은 문자열 하나만 받는다.

해결

# mybatis 설정
mybatis:
  mapper-locations: classpath:mybatis/mapper/*.xml
  config-location: classpath:mybatis/config/mybatis-config.xml

 

728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함