본문으로 바로가기

Mybatis mapperLocations 설정

category Backend/Spring 2021. 5. 21. 17:46
    반응형

    공식 문서

    프로퍼티로 입력된 String type 의 경로 패턴은 PathMatchingResourcePatternResolver 에 의해 해석되어 주입된다.
    스프링 javadoc api 를 살펴 보았다.
    Spring doc

    There is special support for retrieving multiple class path resources with the same name, via the"classpath*:"prefix.
    For example,"classpath*:META-INF/beans.xml"will find all "beans.xml" files in the class path, be it in "classes" directories or in JAR files.

    결론

    classpath: 대신 classpath*: 를 사용해야만 jar 파일의 classpath 디렉토리까지 resolve 된다.
    아래와 같이 path 를 수정하니 정상적으로 패턴에 만족하는 모든 xml 파일이 스캔되었다.

    <bean id\="mySqlSessionFactory" class\="org.mybatis.spring.SqlSessionFactoryBean"\> 
        <property name\="dataSource" ref\="myDataSource" /> 
        <property name\="mapperLocations" value\="classpath\*:mapper/\*.xml" /> 
    </bean\>
    반응형