Skip to content

tuyucheng7/spring-boot-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Examples

Language License MIT Lines of Code Coverage Quality Gate Status All Contributors

这个项目是Spring Boot的一个教程,它包含了Spring Boot的各种示例。其中Spring Boot 2示例和Spring Boot 3示例通过Maven Profiles进行隔离。

多版本JDK构建

就目前而言,大多数模块都是基于JDK 8/17和Spring Boot 2.7.5构建和运行。此外,还有一些项目是基于JDK 17/19和Spring Boot 3.0.2构建的。我们通过Maven ToolChains工具来保证这些模块能够使用单独的JDK构建。

首先,你需要同时下载这些版本(8、17、19)的JDK。然后配置Maven ToolChains,在你用户目录下的.m2文件夹中添加一个toolchains.xml文件:

然后指定以下内容(务必将每个版本的<jdkHome>指向你本地该JDK版本的位置,例如D:\\xxx\\jdk-17):

<?xml version="1.0" encoding="UTF-8"?>
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>17</version>
            <vendor>adopt</vendor>
        </provides>
        <configuration>
            <jdkHome>your jdk 17 path</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>8</version>
            <vendor>adopt</vendor>
        </provides>
        <configuration>
            <jdkHome>your jdk 8 path</jdkHome>
        </configuration>
    </toolchain>
    <toolchain>
        <type>jdk</type>
        <provides>
            <version>19</version>
            <vendor>adopt</vendor>
        </provides>
        <configuration>
            <jdkHome>your jdk 19 path</jdkHome>
        </configuration>
    </toolchain>
</toolchains>

Maven Profiles

我们使用Maven Profile来隔离Spring Boot 2和3模块列表,这些项目大致分为:boot2(Spring Boot 2)、boot3(Spring Boot 3)。接下来,根据我们要执行的测试进一步隔离它们:

Profile 包含 启用的测试类型
boot2-unit Spring Boot 2项目 *UnitTest
boot2-integration Spring Boot 2项目 *IntegrationTest
boot2-all Spring Boot 2项目 *IntegrationTest、*UnitTest
boot3-unit Spring Boot 3项目 *UnitTest
boot3-integration Spring Boot 3项目 *IntegrationTest
boot3-all Spring Boot 3项目 *IntegrationTest、*UnitTest

构建项目

尽管不需要经常一次构建整个仓库,因为我们通常关注特定的模块。

但是,如果我们想在仅启用单元测试的情况下构建整个仓库,我们可以从仓库的根目录调用以下命令:

mvn clean install -Pboot2-unit,boot3-unit

或者,如果我们想在启用集成测试的情况下构建整个仓库,我们可以执行以下操作:

mvn clean install -Pboot2-integration,boot3-integration

构建单个模块

要构建特定模块,请在模块目录中运行命令:

mvn clean install

运行Spring Boot模块

要运行Spring Boot模块,请在模块目录中运行命令:

mvn spring-boot:run

导入到IDE

此仓库包含大量模块,当你使用单个模块时,无需导入所有模块(或构建所有模块)-你可以只需在Eclipse或IntelliJ中导入该特定模块即可。

当你将项目导入到Intellij IDEA中时,默认不会加载任何子模块。你需要在IDE中转到Maven -> Profiles,然后选择你想要构建的子模块所属的Profile,最后刷新等待IDE索引构建完成:

运行测试

模块中的命令mvn clean install将运行该模块中的单元测试,这也将运行SpringContextTest(如果存在)。

要同时运行单元和集成测试,请使用以下命令:

mvn clean install -Pboot2-all

或者

mvn clean install -Pboot3-all

取决于我们的模块所在的列表。

模块列表

贡献人员


tuyucheng

📆 🚧 🖋

taketoday

🖋

About

spring boot examples

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published