增加 spring boot jar 启动原理

This commit is contained in:
YunaiV
2020-06-04 08:45:28 +08:00
parent 7db69bfb03
commit d511da8ab4
4 changed files with 44 additions and 2 deletions

View File

@@ -34,6 +34,7 @@
* [《芋道 Spring Boot 快速入门》](http://www.iocoder.cn/Spring-Boot/quick-start/?github)
* [《芋道 Spring Boot 自动配置原理》](http://www.iocoder.cn/Spring-Boot/autoconfigure/?github) 对应 [lab-47](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-47)
* [《芋道 Spring Boot 芋道 Spring Boot Jar 启动原理》](http://www.iocoder.cn/Spring-Boot/jar/?github)
## 开发工具

View File

@@ -18,6 +18,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-loader</artifactId>-->
<!-- </dependency>-->
</dependencies>
<build>

View File

@@ -3,10 +3,47 @@ package cn.iocoder.springboot.lab39.skywalkingdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.IOException;
import java.net.URISyntaxException;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
public static void main(String[] args) throws URISyntaxException, IOException {
// ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
// CodeSource codeSource = protectionDomain.getCodeSource();
// URI location = (codeSource != null) ? codeSource.getLocation().toURI() : null;
// String path = (location != null) ? location.getSchemeSpecificPart() : null;
// if (path == null) {
// throw new IllegalStateException("Unable to determine code source archive");
// }
// File root = new File(path);
// System.out.println(root + "" + root.isDirectory());
// // 创建 Archive 对象
// Archive archive = new JarFileArchive(root);
// // 创建 EntryFilter 对象
// Archive.EntryFilter filter = new Archive.EntryFilter() {
//
// static final String BOOT_INF_CLASSES = "BOOT-INF/classes/";
//
// static final String BOOT_INF_LIB = "BOOT-INF/lib/";
//
// @Override
// public boolean matches(Archive.Entry entry) {
// // 如果是目录的情况,只要 BOOT-INF/classes/ 目录
// if (entry.isDirectory()) {
// return entry.getName().equals(BOOT_INF_CLASSES);
// }
// // 如果是文件的情况,只要 BOOT-INF/lib/ 目录下的 `jar` 包
// return entry.getName().startsWith(BOOT_INF_LIB);
// }
//
// };
// // 执行读取
// for (Archive item : archive.getNestedArchives(filter)) {
// System.out.println(item.getUrl());
// }
SpringApplication.run(Application.class, args);
}

View File

@@ -32,7 +32,7 @@
<!-- <module>lab-19</module>-->
<!-- <module>lab-20</module>-->
<!-- <module>lab-21</module>-->
<!-- <module>lab-22</module>-->
<module>lab-22</module>
<!-- <module>lab-23</module>-->
<!-- <module>lab-24</module>-->
<!-- <module>lab-25</module>-->