Maven builds spring boot multi-module project

Source: Internet
Author: User

Maven builds spring boot multi-module project

Note: All projects are created in idea

1.idea Creating a Maven project
    • 1-1: Delete src , target directory, keep onlypom.xml

    • 1-2: The root directory pom.xml can be inherited by the module, so the project is only demo, not considering too many performance issues, so many dependent

      都写在根级`pom.xml`,子模块只需继承就可以使用。
    • 1-3: root-level pom.xml files in Appendix 1

    • 1-4: Dependent module MyBatis spring-boot related modules

2. Creating a submodule (module)
    • 2-1: file > new > module Inputmodel

    • 2-2: file > new > module Inputdao

    • 2-3: file > new > module Inputservice

    • 2-4: file > new > module Inputwebapi

3. Modify sub-module Pom.xml configuration
<?xml version="1.0" encoding="UTF-8"?><Projectxmlns="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: <font color= "Red" > <relativePath>../pom.xml</relativePath> </font> This segment must be added to inherit the parent module

At this point, the infrastructure of the project has been built, the next can be the code, OH oh wait, I first introduce the sub-module of the job responsibilities it

4. Sub-modules ' job responsibilities ' in the project
    • modelThis module holds all the entity classes

    • daoThis module holds the specific implementation of data interaction for service invocation

    • serviceThis module holds the business code implementation for the API layer to invoke

    • webapiThis module can also not appear in the project, in order to write the demo so the WEBAPI layer is put in

5. modelLayer entity class writing
    • Create Package Namecom.luyh.projectv1.model

    • Build entity class Member.java specific code please clone my git,git address at the bottom

6. daoLayer Database Operations Layer
    • Build Com.luyh.projectv1.dao.config with only 2 configuration Java classes in the package that let spring boot automatically load the configuration

    • Build Membermapper.java specific content to see the code

    • Build Membermapper.xml under the Resources/mybatis

    • Establish Imember.java

    • Establishing Member.java to implement Imember interface

    • Establishing a resources/application.properties file for configuring database connections

7. serviceWriting business logic
    • Create a com.luyh.projectv1.service Package

    • Establishing the Imemberservice.java interface

    • Establishing the Memberservice.java implementation class

    • The Memberservice.java class automatically injects Daomember and calls its methods to get the data

8. webapiWrite WEBAPI get JSON data
    • Establish Application.java Launch application

    • Create com.luyh.projectv1.webapi.controller.MemberController.java a REST style controller

    • Start

9.sql file Please import MySQL data sql file yourself

Here is the project address, click to download

Appendix 1
<?xml version="1.0" encoding="UTF-8"?><Projectxmlns="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><!--affirm 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 up maven Warehouse--<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>< Span class= "Hljs-tag" ></PROJECT>        

 

Maven builds spring boot multi-module project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.