spring-boot有自己的类加载器:加载BOOT-INF下所有类,一般来说所有类+jar都会copy到BOOT-INF下,JarLauncher启动,注意其parent为appClassLoader,因此appClassLoader基本很难加载到类
spring-boot+tomcat+jar:spring-boot classloader加载BOOT-INF下所有类+资源(包括前端资源),tomcat生成了TomcatEmbeddedWebappClassLoader(其加载路径为WEB-INF),其parent为spring-boot的classloader,tomcat的classloader很难起到实际加载作用
spring-boot+tomcat+war:spring-boot classloader加载WEB-INF下所有类+资源(包括前端资源),WarLauncher启动,同理,tomcat的classloader很难起到实际加载作用
为什么tomcat的classloader很难起到实际加载作用,但必须还存在呢?
tomcat的Context需要一个Webappclassloader,并且设置为用户线程的contextClassLoader(StandardHostValve-contex.bind),用户线程用此classLoader加载其关联的web app下的类,所以spring boot为了兼容tomcat的设计才有此classLoader,但要么没有WEB-INF,要么WEB-INF被其parent给加载了,所以其实际很难加载到类
最后
以上就是潇洒指甲油最近收集整理的关于spring-boot类加载体系的全部内容,更多相关spring-boot类加载体系内容请搜索靠谱客的其他文章。
发表评论 取消回复