# Configuration

> Example code is available on [github.com/vaadin-on-grails/mybatis](https://github.com/vaadin-on-grails/mybatis).

Because Grails is based on Spring, we can use [mybatis-spring](http://mybatis.github.io/spring/) library to integrate [MyBatis](http://mybatis.github.io/mybatis-3/index.html) into Grails.

## Step 1

Add [mybatis](http://mvnrepository.com/artifact/org.mybatis/mybatis) and [mybatis-spring](http://mvnrepository.com/artifact/org.mybatis/mybatis-spring) dependencies into `BuildConfig.groovy`.

```java
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

```java
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"
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ondrej-kvasnovsky-2.gitbook.io/vaadin-on-grails/database/mybatis/configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
