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
model
This module holds all the entity classes
dao
This module holds the specific implementation of data interaction for service invocation
service
This module holds the business code implementation for the API layer to invoke
webapi
This module can also not appear in the project, in order to write the demo so the WEBAPI layer is put in
5.
model
Layer 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.
dao
Layer 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.
service
Writing 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.
webapi
Write WEBAPI get JSON data
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