How to Build a Multi‑module Spring Boot + MyBatis Project in IntelliJ IDEA

This tutorial walks through setting up a Spring Boot and MyBatis multi‑module backend project in IntelliJ IDEA, covering environment preparation, directory layout, parent and sub‑module creation, code examples, dependency configuration, MyBatis integration, and final verification of the running service.

Top Architect
Top Architect
Top Architect
How to Build a Multi‑module Spring Boot + MyBatis Project in IntelliJ IDEA

In this article the author records the process of building a Spring Boot + MyBatis multi‑module project in IntelliJ IDEA, targeting a typical enterprise backend architecture.

Tools and environment : IntelliJ IDEA 2018.2 on macOS.

Project structure : three layers – biz (business), dao (persistence) and web (controller).

Step 1 – Create parent project : Use IDEA → File → New → Project, select Spring Initializr, configure and finish. The resulting directory tree is shown in the screenshots.

Step 2 – Add sub‑modules : Right‑click the parent, New → Module, choose Maven, set artifactId (beta‑biz, beta‑dao, beta‑web) and finish.

Step 3 – Write a simple controller in com.yibao.beta.web:

package com.yibao.beta.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication(scanBasePackages = "com.yibao.beta")
@RestController
@RequestMapping("demo")
public class BetaWebApplication {
    public static void main(String[] args) {
        SpringApplication.run(BetaWebApplication.class, args);
    }

    @GetMapping("test")
    public String test() {
        return "Hello World!";
    }
}

Running the application yields http://localhost:8080/demo/test with “Hello World!”.

Step 4 – Configure inter‑module dependencies in the parent pom.xml using <dependencyManagement> and add the appropriate <dependency> entries in each sub‑module.

Step 5 – Integrate MyBatis : add mybatis-spring-boot-starter and lombok to the parent pom, configure application.properties with datasource and MyBatis settings, generate DAO classes with MyBatis Generator, and inject UserMapper into the service layer.

Sample service implementation:

package com.yibao.beta.biz.service.impl;
import com.yibao.beta.biz.service.DemoService;
import com.yibao.beta.dao.entity.UserDO;
import com.yibao.beta.dao.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DemoServiceImpl implements DemoService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public String test() {
        UserDO user = userMapper.selectByPrimaryKey(1);
        return user.toString();
    }
}

After adding @MapperScan("com.yibao.beta.dao.mapper") to the main class, the application starts successfully and the endpoint returns the user record.

Conclusion : The tutorial demonstrates a clean multi‑module backend layout that facilitates maintenance and future micro‑service migration, and mentions possible extensions such as common, server, logback, disconf, Redis, Dubbo, etc.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MyBatisMulti‑modulebackend-developmentspring-boot
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

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.