Maven build spring boot multi-module project

1.idea Create a maven project

1-1: Delete the src, target directory, leaving only pom.xml

1-2: root directory pom.xml can be sub-module inheritance, the project is just demo, not consider too many performance issues, so many dependencies

Are written in the root level pom.xml, sub-module can be used only to inherit.

1-3: The root level pom.xml file is in Appendix 1

1-4: depend on the module mybatis spring-boot related modules

2. Create a sub-module (module)

2-1: file> new> module Enter the model

2-2: file> new> module Enter dao

2-3: file> new> module Enter service

2-4: file> new> module Enter webapi

3. Modify the submodule pom.xml configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<? Xml version = "1.0" encoding = "UTF-8"?>
<Project xmlns = "http://maven.apache.org/POM/4.0.0"
         Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
         Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <Parent>
        <ArtifactId> parent </ artifactId>
        <GroupId> com.luyh.projectv1 </ groupId>
        <Version> 1.0-SNAPSHOT </ version>
        <RelativePath> ../ pom.xml </ relativePath>
    </ Parent>
    <ModelVersion> 4.0.0 </ modelVersion>

    <ArtifactId> projectv1-model </ artifactId>
</ Project>

Note: ../pom.xml This section must be added to inherit the parent module

At this point, the project’s infrastructure structure is completed, the next line of code can be, oh oh wait, I first introduce the work of the various sub-module responsibilities

4. Sub-module in the project as the ‘job responsibilities’

This module holds all entity classes

Dao This module holds the concrete realization of data interaction for service call

Service This module holds the business code implementation for API level invocation

Webapi this module can not appear in the project, in order to write demo webapi layer will come in

5.model layer entity class written

Create the package name com.luyh.projectv1.model

Construction entity class Member.java specific code Please clone my git, git address in the bottom

6.dao layer database operation layer

The establishment of com.luyh.projectv1.dao.config, the package is only 2 to spring boot automatically configured to configure

the configuration of java class

MemberMapper.java specific content to see the code

Create a MemberMapper.xml under resources / mybatis

Create IMember.java

Create Member.java Imember interface

Create the resources / application.properties file to configure the database connection

7. Service write business logic

Create the com.luyh.projectv1.service package

Create the IMemberService.java interface

Create a MemberService.java implementation class

The MemberService.java class automatically injects DaoMember and calls its methods to get the data

8. webapi Write webapi to get json data

Build Application.java Start the application

Create com.luyh.projectv1.webapi.controller.MemberController.java write a rest style Controller

start up

9.sql file Please import mysql data sql file

Here is the project address, click to download

Appendix 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

<? Xml version = "1.0" encoding = "UTF-8"?>
<Project xmlns = "http://maven.apache.org/POM/4.0.0"
         Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
         Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <ModelVersion> 4.0.0 </ modelVersion>

    <GroupId> com.luyh.projectv1 </ groupId>
    <ArtifactId> parent </ artifactId>
    <Version> 1.0-SNAPSHOT </ version>
    <Packaging> pom </ packaging>
    <Parent>
        <GroupId> org.springframework.boot </ groupId>
        <ArtifactId> spring-boot-starter-parent </ artifactId>
        <Version> 1.3.3.RELEASE </ version>
    </ Parent>
    <Modules>

        <Module> model </ module>
        <Module> dao </ module>
        <Module> service </ module>
        <Module> webapi </ module>
    </ Modules>

    <! - Declare Dependencies ->
    <Dependencies>
        <Dependency>
            <GroupId> org.springframework.boot </ groupId>
            <ArtifactId> spring-boot-starter-web </ artifactId>
        </ Dependency>

        <Dependency>
            <GroupId> org.springframework.boot </ groupId>
            <ArtifactId> spring-boot-starter-jdbc </ artifactId>
        </ Dependency>

        <Dependency>
            <GroupId> org.mybatis </ groupId>
            <ArtifactId> mybatis-spring </ artifactId>
            <Version> 1.2.2 </ version>
        </ Dependency>
        <Dependency>
            <GroupId> org.mybatis </ groupId>
            <ArtifactId> mybatis </ artifactId>
            <Version> 3.2.8 </ version>
        </ Dependency>

        <Dependency>
            <GroupId> org.apache.tomcat </ groupId>
            <ArtifactId> tomcat-jdbc </ artifactId>
        </ Dependency>

        <Dependency>
            <GroupId> mysql </ groupId>
            <ArtifactId> mysql-connector-java </ artifactId>
        </ Dependency>
    </ Dependencies>

    <! - Set maven repository ->

    <Repositories>
        <Repository>
            <Id> spring-releases </ id>
            <Url> https://repo.spring.io/libs-release </ url>
        </ Repository>
    </ Repositories>
    <PluginRepositories>
        <PluginRepository>
            <Id> spring-releases </ id>
            <Url> https://repo.spring.io/libs-release </ url>
        </ PluginRepository>
    </ PluginRepositories>


</ Project>

ref

spring-boot
example code