Vaadin 7 on Grails 2.x
  • Introduction
  • Project setup
    • Command Line
    • IntelliJ IDEA
    • Eclipse
    • NetBeans
    • Plugin Configuration
    • 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
      • Execute SQLs
    • MyBatis
      • Configuration
      • Basics
    • JdbcTemplate
      • Create Beans
      • Usage
    • Clean Up With Alternatives
  • Architecture
    • Model View Presenter
  • Spring Autowiring
    • Create Simple Application
    • Application With Navigator
  • UI
    • Re-using GORM Validations
    • Async Push
    • Multiple application
    • SASS Compilation
    • Widgetset Compilation
  • Spring Security
    • Spring Security Dependency
    • Spring Security Basics
    • Secured Navigator
  • Localization
    • Localization Basics
    • Custom MessageSource
  • REST
    • Without using root URL
    • Using root URL for Vaadin app
  • Plugin development
    • Github
    • Development
Powered by GitBook
On this page
  • Step 1
  • Step 2

Was this helpful?

  1. Database
  2. MyBatis

Configuration

PreviousMyBatisNextBasics

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