本文介绍了Java EE 类加载标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebSphere 最后是父级,父级在前.这是否符合 Java EE?是否所有符合 Java EE 5 的应用服务器都支持这一点?

WebSphere comes with parent last and parent first. Is this Java EE compliant? Is this supported by all application servers that are Java EE 5 compliant?

推荐答案

我做了我自己的研究(浏览了规范和一些博客),下面是我的想法

I did my own research (going through the specs and few blogs) and below is what I've figured

耳朵

规范没有定义或强制要求类加载器在 EAR 中应该如何工作.然而,它定义了

The spec DOES NOT define or mandate how the class loaders should work within an EAR. It however defines that 

  1. 应该有每个线程上下文类加载器,用于运行时加载类
  2. 可能存在用于解析类的分层类加载机制(应用服务器供应商可以自由地实施他们选择的任何方式)
  3. 顶级类加载器 (WAR/EAR) 可以委托给低级类加载器(如 Bootstrap、扩展等).这符合 J2SE 类加载器委托模型(WAS 中的 PARENT_FIRST)

战争

Servlet 规范定义并强制支持 PARENT_LAST(即 WAR/web-inf/classes 和 WAR/web-inf/lib 优先于应用服务器附带的库)类加载模型.但这仅适用于 WAR 模块.在这种情况下,Servlet 规范与 PARENT_FIRST 的标准 J2SE 委托模型不同.

Servlet specification defines and mandates the support of a PARENT_LAST (i.e. WAR/web-inf/classes and WAR/web-inf/lib take precedence over the libraries that come with the app server) class loading model. But this is just for WAR modules. The Servlet spec diverges from the standard J2SE delegation model of PARENT_FIRST in this case.

参考

规范:Servlet 2.3,部分:9.7.2 Web 应用程序类加载器

Spec: Servlet 2.3, Section: 9.7.2 Web Application Classloader

规范:Java EE 5,部分:EE.6.2.4.7 上下文类加载器

Spec: Java EE 5, Section: EE.6.2.4.7 Context Class Loader

应用服务器细节

然而,有趣的是,大多数主要应用服务器似乎都支持某种机制,在必要时(由于冲突或其他原因)关闭委托以将应用程序与应用服务器隔离:WebSphere -父级",GlassFish - <class-loader delegate="false">, JBoss - java2ParentDelegation=false, Geronimo - false</java2-delegation-模型>

Interestingly, though, it appears most major app servers support some mechanism of turning off delegation to isolate the application from the app server if necessary (because of conflicts or otherwise): WebSphere - "parent-last", GlassFish - <class-loader delegate="false">, JBoss - java2ParentDelegation=false, Geronimo - <java2-delgation-model>false</java2-delegation-model>

这篇关于Java EE 类加载标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 07:54