Setting Up MyBatis with Maven
Harry
· 11 Sep 2026
· 9 views
Adding the Dependency
Add the MyBatis library to your project. Both the core library and the Spring Boot starter are available on Maven Central.
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.16</version>
</dependency>For Spring Boot
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>Add a JDBC Driver
<!-- MySQL -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>Minimal Project Layout
src/
main/java/com/example/app/
domain/Customer.java
mapper/CustomerMapper.java
main/resources/
mybatis-config.xml
mapper/CustomerMapper.xml
application.propertiesKey Points
- Add the mybatis dependency (or the Spring Boot starter).
- Include the JDBC driver for your database.
- Organize code into domain objects and mapper interfaces.
- XML mapper files live under main/resources.