springboot的类加载器(...类加载器的分类。
试验:使⽤maven打包
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>启动类的完整路径</mainClass>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
各个配置项的作⽤⾃⾏百度~
这样⽣成的jar包,⽤压缩⼯具打开以后是这样
在META-INF下打开MANIFEST.MF⽂件看看(记事本就可以打开)springframework作用
可以看到这⾥的类加载器是:PropertiesLauncher,⽂档百度翻译如下:
Launcher for archives with user-configured classpath and main class via a properties file. This model is often more flexible and more amenable to creating well-behaved OS-level services than a model based on executable jars.
Looks in various places for a properties file to extract loader settings, defaulting to application.properties either on the current classpath or in the current working directory. The name of the properties file can be changed by setting a System fig.name (e.g. -fig.name=foo will look for foo.properties. If that file doesn't exist then fig.location (with allowed prefixes classpath: and file: or any valid URL). Once that file is located turns it into Properties and extracts optional values (which can also be provided overridden as System properties in case the file doesn't exist):
loader.path: a comma-separated list of directories (containing file resources and/or nested archives in .jar or .zip or archives) or archives to append to the classpath. BOOT-INF/classes,BOOT-INF/lib in the application archive are always used
loader.main: the main method to delegate execution to once the class loader is set up. No default, but will fall back to looking for a Start-Class in a MANIFEST.MF, if there is one in ${loader.home}/META-INF.
启动程序,⽤于通过属性⽂件使⽤⽤户配置的类路径和主类进⾏归档。与基于可执⾏jar的模型相⽐,这种模型通常更灵活,更易于创建性能良好的OS级服务。
在不同位置查属性⽂件以提取加载程序设置,默认为应⽤程序.属性在当前类路径或当前⼯作⽬录中。属性⽂件的名称可以通过设置系统属性来更改加载程
序.config.name(例如-fig.name=foo会寻⾷品属性. 如果该⽂件不存在,则尝试fig.location(使⽤允许的前缀classpath:和file:或任何有效的URL)。到该⽂件后,将其转换为属性并提取可选值(如果该⽂件不存在,也可以将其作为系统属性进⾏覆盖):
加载程序.path:以逗号分隔的⽬录列表(包含⽂件资源和/或.jar或.zip中的嵌套存档⽂件)或要附加到类路径的存档⽂件。总是使⽤应⽤程序档案中的BOOT-INF/classes、BOOT-INF/lib
装载机.main:设置类装⼊器后将执⾏委托给的主⽅法。没有默认值,但将返回到在清单.MF,如果有${装载机.home}/中导。
这种也是配置:使⽤jar包外部的配置⽂件的启动⽅式的⽅法。在linux我们的启动脚本要使⽤对应的类加载器来启动。
如果你配置成其他的(<layout>ZIP</layout>此配置项去掉,main-class就会变成JarLauncher)⽐如:JarLauncher
Launcher for JAR based archives. This launcher assumes that dependency jars are included inside a /BOOT-INF/lib directory and that application classes are included inside
a /BOOT-INF/classes directory.
基于JAR的档案的启动程序。这个启动程序假设依赖项jar包含在/BOOT-INF/lib⽬录中,应⽤程序类包含在/BOOT-INF/classes⽬录中。
就会有如下的错误:项⽬启动失败。
springboot项⽬启动,调⽤的是相应的类加载器的main⽅法,⽽不是我们⾃⼰编写的SpringApplication
Spring Boot Loader提供了⼀套标准⽤于执⾏SpringBoot打包出来的jar,这套标准就是我们的类加载器
下⾯是⼀个例⼦,图中有构造⽅法,和类⽅法。
友情链接
到此这篇关于springboot的类加载器(org.springframework.boot.loader)的⽂章就介绍到这了,更多相关springboot类加载器内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。