Backend Development 11 min read

Step‑by‑Step Guide to Building a SpringBoot + MyBatis Multi‑Module Project in IntelliJ IDEA

This tutorial walks through setting up a SpringBoot‑based multi‑module Maven project with MyBatis integration in IntelliJ IDEA, covering environment preparation, parent and child module creation, dependency configuration, package scanning, and verification of a simple REST endpoint, while highlighting common pitfalls and solutions.

Top Architect
Top Architect
Top Architect
Step‑by‑Step Guide to Building a SpringBoot + MyBatis Multi‑Module Project in IntelliJ IDEA

1. Introduction

The article documents the complete process of constructing a SpringBoot + MyBatis multi‑module project using IntelliJ IDEA, aimed at developers who need a clean, layered architecture for future micro‑service migration.

2. Development tools and environment

IDE: IntelliJ IDEA 2018.2

System: macOS

3. Project directory structure

biz layer – business logic

dao layer – data persistence

web layer – request handling

4. Building steps

4.1 Create parent project

In IDEA select File → New → Project… , choose Spring Initializr , keep the default settings and click Next . Fill the group and artifact information and finish the wizard.

After creation delete the unnecessary .mvn , src , mvnw and mvnw.cmd files, leaving only .gitignore and pom.xml .

4.2 Create child modules

Right‑click the parent directory, choose New → Module , select Maven , fill the artifactId (e.g., beta-biz , beta-dao , beta-web ) and finish. The final structure looks like:

4.3 Run the project

Create the entry class BetaWebApplication.java in package com.yibao.beta.web :

@SpringBootApplication
public class BetaWebApplication {
    public static void main(String[] args) {
        SpringApplication.run(BetaWebApplication.class, args);
    }
}

Add a simple controller:

@RestController
@RequestMapping("demo")
public class DemoController {
    @GetMapping("test")
    public String test() { return "Hello World!"; }
}

Running the main method starts the application on port 8080; accessing http://localhost:8080/demo/test returns the expected response.

4.4 Configure inter‑module dependencies

In the parent pom.xml declare the modules under dependencyManagement and add the required dependencies in each child module, for example:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.yibao.beta</groupId>
            <artifactId>beta-biz</artifactId>
            <version>${beta.version}</version>
        </dependency>
        ...
    </dependencies>
</dependencyManagement>

Also add the beta-biz dependency to beta-web and beta-dao dependency to beta-biz .

4.5 Integrate MyBatis

Add mybatis-spring-boot-starter and lombok to the parent dependencyManagement , then include them in the beta-dao module.

Generate DAO classes (DO, Mapper, XML) with MyBatis Generator and place them under com.yibao.beta.dao . Example application.properties configuration:

spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://192.168.1.1/test?useUnicode=true&characterEncoding=utf-8
spring.datasource.username = test
spring.datasource.password = 123456
mybatis.mapper-locations = classpath:mybatis/*.xml
mybatis.type-aliases-package = com.yibao.beta.dao.entity

Inject the generated UserMapper into DemoServiceImpl and return data from the database.

4.6 Resolve bean‑scanning issues

If the application fails with “required a bean of type … could not be found”, add package scanning to the entry class:

@SpringBootApplication(scanBasePackages = "com.yibao.beta")
@MapperScan("com.yibao.beta.dao.mapper")
public class BetaWebApplication { ... }

After these adjustments the project starts successfully and the endpoint /demo/test returns the expected result.

5. Summary

The guide demonstrates a clear, layered multi‑module architecture that simplifies maintenance and prepares the codebase for future micro‑service extraction. Additional layers such as a common utilities module or a Dubbo service module can be added on top of this foundation.

6. Common pitfalls

During setup, an internal Maven repository that mirrors Alibaba’s central repository may lack some artifacts, causing build failures; ensure the repository provides a complete set of dependencies.

JavamavenMyBatisSpringBootIDEAMulti-Module
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.