构建spring boot web项目:一、创建spring boot项目

目录

前言

一、创建父项目(initMode)

 二、创建通用模块(common)

 2.1 创建基础封装模块(base)

三、创建服务应用聚合模块(service)

3.1创建管理应用模块(management)

 3.2配置logback日志系统

四、创建功能组件模块(function)

五、测试

六、完整pom.xml

前言

本文使用模块化简单构建一个spring boot web后端项目,集成了Mybatis-plus、redis、文件存储minio、RabbitMQ、knife4j、Elasticsearch、shiro等组件,各个组件以模块的形式存在,可以根据自身需要进行集成使用;实现了统一返回、统一异常处理、权限认证、接口API等功能;另外,各个组件只是简单的使用,如要实现复杂功能还需自行研究;

一、创建父项目(initMode)

删除src文件夹

编辑pom.xml(initMode)

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.7.RELEASE</version>
    </parent>
    <groupId>com.lyj.initMode</groupId>
    <artifactId>initMode</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>initMode</name>
    <packaging>pom</packaging>

    <description>初始化构建spring boot web项目</description>

    <modules>
    </modules>
    <properties>
        <!-- maven打包时跳过测试 -->
        <skipTests>true</skipTests>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <!--编译-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 二、创建通用模块(common)

删除pom.xml以外其他文件

编辑common/pom.xml

<?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>
    <parent>
        <groupId>com.lyj.initMode</groupId>
        <artifactId>initMode</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>citc-lyj-common</artifactId>
    <packaging>pom</packaging>

    <description>通用模块</description>

    <modules>
    </modules>

</project>

 编辑pom.xml(initMode),将common模块加入到父模块

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.7.RELEASE</version>
    </parent>
    <groupId>com.lyj.initMode</groupId>
    <artifactId>initMode</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>initMode</name>
    <packaging>pom</packaging>

    <description>初始化构建spring boot web项目</description>

    <modules>
        <module>common</module>
    </modules>
    <properties>
        <!-- maven打包时跳过测试 -->
        <skipTests>true</skipTests>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <!--编译-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 2.1 创建基础封装模块(base)

编辑pom.xml(initMode-common-base) 引入基础依赖

<?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>
    <parent>
        <groupId>com.lyj.initMode</groupId>
        <artifactId>initMode-common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>initMode-common-base</artifactId>
    <packaging>jar</packaging>

    <description>基础封装模块</description>

    <dependencies>
        <!--web依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--spring boot 单元测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <!--json工具-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <!--常用工具包-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <!--常用io工具包-->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <!--AOP-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <!--引入lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!--引入Hutool工具类-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.16</version>
        &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值