随着微服务的普及应用,springboot作为spring占领行业微服务的拳头,可能你早已熟练使用它去开发业务功能。当然,你可能知道springboot项目打成的jar可以直接运行,可能你也知道它的原理,但你真的知道它的原理吗,没有亲自debug下,可能就不那么肯定了吧。本文就来debug说下,springboot jar开始运行的真正起点:真正的main方法在哪里,怎么运行的
理论
为了方便阐述,理论先摆出
我假定创建一个spring boot 项目:microservice-comb-server,下面的jar都指这个项目的jar
在项目的pom.xml中引入了spring-boot-maven-plugin
,生成的jar就可以直接运行了。如下配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
因为引入了spring-boot-maven-plugin
,package
生成的jar里包含META-INF/MANIFEST.MF