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. openstack实验环境搭建

    Openstack实验文档 一.base节点 1.1配置网络 vim /etc/sysconfig/network-scripts/ifcfg-eth0 1.2关闭防火墙和selinux system ...

  2. DML语言DDL

    DML(data manipulation language): 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言 . D ...

  3. 宽度总结-scrollWidth,clientWidth,offectWidth

    平时写js的时候,有时候会遇到这样的情况,需要去计算元素或者屏幕的宽度,再进行不同的处理,但是宽度真的有不少,很容易搞混,特此总结下,也希望大家亲测下,这样比较有体会,记得牢固些. 1.scrollW ...

  4. bootstrap table 父子表实现【无限级】菜单管理功能

    bootstrap table 父子表实现[无限级]菜单管理功能 实现效果 前端代码 <%@ page language="java" import="java.u ...

  5. WPF音乐电台

    最近一两年都没写过wpf相关的项目了,本来就不太熟的一些技巧全忘光啦,为了重新拾起这点东西,就花了几天时间做了个小demo,大致功能就是读取豆瓣电台api,获取歌单列表听歌.最开始是参考网上现有的例子 ...

  6. Appium+python自动化(二十三)- 真假美猴王Monkeyrunner与Monkey傻傻的分不清楚(超详解)

    简介 看<西游记>第五十七回,说是“六耳猕猴”化作孙悟空的摸样,伤了唐僧,后又和孙悟空大打出手…… 这位假孙悟空,实力不用多说了吧,和真孙悟空一般无二,大战孙悟空,闹到上天入地下海. 在唐 ...

  7. C 单链表 实现约瑟夫环

    list.h #ifndef _List_H #define _List_H typedef int ElementType; struct Node; typedef struct Node *Pt ...

  8. dede:channelartlist currentstyle高亮显示

    我们在用DEDECMS建站时,常常会做二级栏目的功能,既要用到二级栏目,也就要通过DEDE标签再套标签的方式来实现调用,而DEDECMS多层标签调用只支持channelartlist,也就是说我们只能 ...

  9. kubernetes二进制高可用部署实战

    环境: 192.168.30.20 VIP(虚拟) 192.168.30.21 master1 192.168.30.22 master2 192.168.30.23 node1 192.168.30 ...

  10. 【TensorFlow 2】矩阵基础

    placeholder placeholder为tf中的占位符,用来保存数据.语法为: tf.placeholder(dtype, shape=None, name=None) dtype:数据类型  ...