Springboot源码分析之项目结构

摘要:

  • 无论是从IDEA还是其他的SDS开发工具亦或是https://start.spring.io/ 进行解压,我们都会得到同样的一个pom.xml文件

    4.0.0

    org.springframework.boot
    spring-boot-starter-parent
    2.1.6.RELEASE

        <groupId>com.github.dqqzj</groupId>
        <artifactId>springboot</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>springboot</name>
        <packaging>jar</packaging>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

parent标签的含义

  • 找到本地仓库的spring-boot-starter-parent 坐标

    4.0.0

    org.springframework.boot
    spring-boot-dependencies
    2.1.6.RELEASE
    ../../spring-boot-dependencies

    spring-boot-starter-parent
    pom
    Spring Boot Starter Parent
    Parent pom providing dependency and plugin management for applications
    built with Maven
    https://projects.spring.io/spring-boot/#/spring-boot-starter-parent

    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <resource.delimiter>@</resource.delimiter>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>${java.version}</maven.compiler.target>

    true
    ${basedir}/src/main/resources

    **/application*.yml
    **/application*.yaml
    **/application*.properties

    ${basedir}/src/main/resources

    **/application*.yml
    **/application*.yaml
    **/application.properties

    org.jetbrains.kotlin
    kotlin-maven-plugin
    ${kotlin.version}

    compile
    compile

    compile

    test-compile
    test-compile

    test-compile

    ${java.version}
    true

    maven-compiler-plugin

    true

    maven-failsafe-plugin

    integration-test
    verify

    ${project.build.outputDirectory}

    maven-jar-plugin

    ${start-class}
    true

    maven-war-plugin

    ${start-class}
    true

    org.codehaus.mojo
    exec-maven-plugin

    ${start-class}

    maven-resources-plugin

    ${resource.delimiter}

    false

    pl.project13.maven
    git-commit-id-plugin

    revision

    true
    yyyy-MM-dd'T'HH:mm:ssZ
    true
    ${project.build.outputDirectory}/git.properties

    org.springframework.boot
    spring-boot-maven-plugin

    repackage

    repackage

    ${start-class}

    maven-shade-plugin

    package

    shade

    META-INF/spring.handlers

    META-INF/spring.factories

    META-INF/spring.schemas

    ${start-class}

    org.springframework.boot
    spring-boot-maven-plugin
    2.1.6.RELEASE

    true
    true

    :

    META-INF/.SF
    META-INF/.DSA
    META-INF/
    .RSA

    org.eclipse.m2e
    lifecycle-mapping
    1.0.0

    org.codehaus.mojo
    flatten-maven-plugin
    [1.0.0,)

    flatten

    org.apache.maven.plugins
    maven-checkstyle-plugin
    [3.0.0,)

    check

关注点
  •   <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-dependencies</artifactId>
          <version>2.1.6.RELEASE</version>
          <relativePath>../../spring-boot-dependencies</relativePath>
        </parent>

说明我们的工程可以进行改造进行替换掉原来工程的parent标签.

  • <plugin>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-maven-plugin</artifactId>
              <executions>
                <execution>
                  <id>repackage</id>
                  <goals>
                    <goal>repackage</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <mainClass>${start-class}</mainClass>
              </configuration>
            </plugin>

    repackage必须要有否则打jar包时候无法正常启动.

在配置文件加上repackage即可

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

IDEA自带maven工具

mvnw是基于linuxshell脚本命令

mvnw.cmd是基于windows的脚本命令

.mvn包含了maven下载路径以及版本等信息

也就是说我们完全不用自己下载maven而是可以直接使用IDEA给我们提供的工具即可,只不过通常不会这么做。

repackage的作用

  • 官方文档
  • 正常情况下打包会生成springboot-0.0.1-SNAPSHOT.jar,original,springboot-0.0.1-SNAPSHOT.jar这样的2个文件,而repackage的作用就是将springboot-0.0.1-SNAPSHOT.jar.original重新打包为我们可以执行的springboot-0.0.1-SNAPSHOT.jar

Springboot源码分析之项目结构的更多相关文章

  1. gperftools源码分析和项目应用 - CPU Profiler

    gperftools源码分析和项目应用 - CPU Profiler 原文:https://blog.csdn.net/yubo112002/article/details/81076821 原文链接 ...

  2. MySQL源码分析以及目录结构 2

    原文地址:MySQL源码分析以及目录结构作者:jacky民工 主要模块及数据流经过多年的发展,mysql的主要模块已经稳定,基本不会有大的修改.本文将对MySQL的整体架构及重要目录进行讲述. 源码结 ...

  3. MySQL源码分析以及目录结构

    原文地址:MySQL源码分析以及目录结构作者:jacky民工 主要模块及数据流经过多年的发展,mysql的主要模块已经稳定,基本不会有大的修改.本文将对MySQL的整体架构及重要目录进行讲述. 源码结 ...

  4. ffplay源码分析2-数据结构

    ffplay是FFmpeg工程自带的简单播放器,使用FFmpeg提供的解码器和SDL库进行视频播放.本文基于FFmpeg工程4.1版本进行分析,其中ffplay源码清单如下: https://gith ...

  5. SpringBoot源码分析之SpringBoot的启动过程

    SpringBoot源码分析之SpringBoot的启动过程 发表于 2017-04-30   |   分类于 springboot  |   0 Comments  |   阅读次数 SpringB ...

  6. IdentityServer4源码解析_1_项目结构

    目录 IdentityServer4源码解析_1_项目结构 IdentityServer4源码解析_2_元数据接口 IdentityServer4源码解析_3_认证接口 IdentityServer4 ...

  7. 从SpringBoot源码分析 配置文件的加载原理和优先级

    本文从SpringBoot源码分析 配置文件的加载原理和配置文件的优先级     跟入源码之前,先提一个问题:   SpringBoot 既可以加载指定目录下的配置文件获取配置项,也可以通过启动参数( ...

  8. springboot源码分析-SpringApplication

    SpringApplication SpringApplication类提供了一种方便的方法来引导从main()方法启动的Spring应用程序 SpringBoot 包扫描注解源码分析 @Spring ...

  9. Springboot源码分析之jar探秘

    摘要: 利用IDEA等工具打包会出现springboot-0.0.1-SNAPSHOT.jar,springboot-0.0.1-SNAPSHOT.jar.original,前面说过它们之间的关系了, ...

随机推荐

  1. 七牛云图床和Markdown使用

    七牛云图床和Markdown使用 1.图床是什么? 图床一般是指储存图片的服务器,有国内和国外之分.国外的图床由于有空间距离等因素决定访问速度很慢影响图片显示速度.国内也分为单线空间.多线空间和cdn ...

  2. 【POJ - 2253】Frogger (Floyd算法)

    -->Frogger 中文翻译 Descriptions: 湖中有n块石头,编号从1到n,有两只青蛙,Bob在1号石头上,Alice在2号石头上,Bob想去看望Alice,但由于水很脏,他想避免 ...

  3. 踩坑 Spring Cloud Hystrix 线程池队列配置

    背景: 有一次在生产环境,突然出现了很多笔还款单被挂起,后来排查原因,发现是内部系统调用时出现了Hystrix调用异常.在开发过程中,因为核心线程数设置的比较大,没有出现这种异常.放到了测试环境,偶尔 ...

  4. vijos p1304 回文数

    N进制下的加法 2/10/16进制下,char到int的转换 #include<iostream>#include<string>using namespace std;str ...

  5. python检测变量名

    python检测变量名 变量在编程中的用途非常广,在python中,变量的名称只能以字母或者下划线“_”开头,变量名只能由字母.数字.下划线组成. 编写python,使得其实现以下功能: 1.输入一个 ...

  6. HTTP_1_Web及网络基础

    Web使用一种HTTP(HyperText TransFer Protocol,超文本协议)的协议作为规范,完成从客户端到服务器等一系列运作流程.可见web是建立在HTTP协议上通信的. 通常我们使用 ...

  7. [原创]一款基于Reactor线程模型的java网络爬虫框架

    AJSprider 概述 AJSprider是笔者基于Reactor线程模式+Jsoup+HttpClient封装的一款轻量级java多线程网络爬虫框架,简单上手,小白也能玩爬虫, 使用本框架,只需要 ...

  8. 工作笔记--对接三方Http接口遇到的问题

    在使用 HttpClient 4.4 调用第三方 http api 时遇到了很多问题,还好最后都解决了,记录一下遇到的问题及解决办法,希望对同样有此问题的你有所帮助. 环境说明 首先说明一点是,对方的 ...

  9. Linux学习笔记05之网络基础知识

    一.OSI参考模型:适用于所有网络,现有模型,后有协议 1.应用层:应用程序.用户接口 2.表示层:编码转换.压缩.解压.加密等 3.会话层:建立.维护.拆除会话 4.传输层规定了应用程序的的接口 协 ...

  10. Github上fork的项目如何merge原Git项目

    问题场景 小明在Github上fork了一个大佬的项目,并clone到本地开发一段时间,再提交merge request到原Git项目,过了段时间,原作者联系小明,扔给他下面这幅截图并告知合并处理冲突 ...