Configuration

Example code is available on github.com/vaadin-on-grails/mybatisarrow-up-right.

Because Grails is based on Spring, we can use mybatis-springarrow-up-right library to integrate MyBatisarrow-up-right into Grails.

Step 1

Add mybatisarrow-up-right and mybatis-springarrow-up-right dependencies into BuildConfig.groovy.

compile 'org.mybatis:mybatis:3.2.7'
compile 'org.mybatis:mybatis-spring:1.2.2'

Step 2

Define new beans in resources.groovy.

  • sqlSessionFactory configures connection factory using XML files at the specified location

  • mapperScannerConfigurer will scan for mappers based on what is defined by basePackage property

import org.apache.commons.dbcp.BasicDataSource
import org.mybatis.spring.SqlSessionFactoryBean
import org.mybatis.spring.mapper.MapperScannerConfigurer

beans = {

    sqlSessionFactory(SqlSessionFactoryBean) {
        dataSource = ref("dataSource")
        mapperLocations = "classpath:com/app/mappers/**/*.xml"
    }

    mapperScannerConfigurer(MapperScannerConfigurer) {
        basePackage = "com.app.mappers"
    }
}

Last updated

Was this helpful?