0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【spring-batch + MyBatis】外部フォルダに格納されたmapper XMLを読み込む

Posted at

環境

spring-batch:4.3.1
Mybatis:3.5.6
Mybatis-Spring:2.0.6

【spring-batch + MyBatis】SqlSessionFactoryBeanのmapperLocations

外部フォルダに格納されたmapper XMLを読み込む方法。
下記のように、SqlSessionFactoryBeanの「mapperLocations」でXMLファイルのロケーションが指定できる。

context.xml
<bean id="reader" class="org.mybatis.spring.batch.MyBatisCursorItemReader"
      p:queryId="org.terasoluna.batch.functionaltest.app.repository.mst.CustomerRepository.findAll" />
    <property name="sqlSessionFactory">
        <bean parent="jobSqlSessionFactory"
            p:dataSource-ref="STATEMENT"
            p:mapperLocations="classpath*:/mapper/**/*.xml" />
    </property>
</bean>

<bean id="jobSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
      p:dataSource-ref="jobDataSource">
    <property name="configuration">
        <!-- 省略 -->
    </property>
</bean>
}

spring-batch + MyBatisでは、Mapper XMLとMapperクラスのパスが同じ場合、上記の指定をしなくてもMybatisがMapper XMLを読み込んでくれる。
そのため、任意のフォルダにMapper XMLを格納したい要件がでた際に指定の仕方がわからず、ちょっと苦労した。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?