spring

[myBatis 오류] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception with message: Failed to parse mapping resource:

seulhasony 2023. 12. 17. 12:51

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception with message: Failed to parse mapping resource: 'file [C:\workspace\projects\challenges\challenges\build\resources\main\mapper\ProductMapper_sql.xml]'

 

myBatis를 설정하고 mapper.java와 sql문이 들어갈 xml파일을 생성하는데 해당 오류가 났다.

 

이유는 xml 파일 안에

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

 

해당 코드가 없었기 때문이다.

 

추가적으로, mybatis 설정을 위한 application.yml 파일 코드도 추가하겠습니다!

mybatis:
  mapper-locations: classpath:mapper/**/*.xml
  configuration:
    map-underscore-to-camel-case: true
  type-aliases-package: 패키지명.mapper

 

**여기서 map-underscore-to-camel-case는 자동으로 카멜로 변경할 것인지 설정하는 것입니다!