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-dependenciesspring-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.propertiesorg.jetbrains.kotlin
kotlin-maven-plugin
${kotlin.version}compile
compilecompile
test-compile
test-compiletest-compile
${java.version}
truemaven-compiler-plugin
true
maven-failsafe-plugin
integration-test
verify${project.build.outputDirectory}
maven-jar-plugin
${start-class}
truemaven-war-plugin
${start-class}
trueorg.codehaus.mojo
exec-maven-plugin${start-class}
maven-resources-plugin
${resource.delimiter}
false
pl.project13.maven
git-commit-id-pluginrevision
true
yyyy-MM-dd'T'HH:mm:ssZ
true
${project.build.outputDirectory}/git.propertiesorg.springframework.boot
spring-boot-maven-pluginrepackage
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.RELEASEtrue
true:
META-INF/.SF
META-INF/.DSA
META-INF/.RSAorg.eclipse.m2e
lifecycle-mapping
1.0.0org.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
是基于linux
的shell
脚本命令
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