Vaadin 8 on Grails 3
  • Introduction
  • Project setup
    • Environment setup
      • Unix based systems
      • Windows
    • Creating Project
      • Command line
      • IntelliJ IDEA
    • Plugin Configuration
      • UI class
      • URL mapping
      • Production mode
      • Async support
      • Themes
      • SASS compilation
      • Widgetset compilation
      • Servlet class
      • Spring component scan
      • UI provider
      • Open session in view
    • Clean up
    • Best Practices
  • Database
    • GORM
      • Create Domain Model
      • Transactions
      • LazyInitializationException
      • Open Session In View I.
      • Open Session In View II.
      • Table Container
    • Groovy SQL
      • Create Sql Bean
      • Execute SQLs
    • MyBatis
      • MyBatis Configuration
      • Reading Data with MyBatis
    • JdbcTemplate
      • Create JdbcTemplate Beans
      • Using JdbcTemplate
    • Clean Up When Using Alternatives
  • UI
Powered by GitBook
On this page
  • Step 1
  • Step 2

Was this helpful?

  1. Database
  2. MyBatis

MyBatis Configuration

PreviousMyBatisNextReading Data with MyBatis

Last updated 5 years ago

Was this helpful?

Example code is available on .

Because Grails is based on Spring, we can use library to integrate into Grails.

Step 1

Add and 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"
    }
}
github.com/vaadin-on-grails/mybatis
mybatis-spring
MyBatis
mybatis
mybatis-spring