The invention discloses a module loading method and a device in a web container, so as to solve the problem of slow lookup of classes in the startup process of the existing Web container. This method is to obtain the blacklist and / or white list of the modules of the pre configured first web application during the web container startup process of the first web application; if the white list of each module is obtained, the class lookup and loading of the modules included in the white list are executed when the class is found by the general class loader; To the blacklist of each module and not to get a white list, when the class is looked up by the general class loader, it is traversing whether each module under the corresponding universal class loading path is included in the blacklist, and if any of the modules under the corresponding universal class loading path are included in the blacklist, it is not aimed at any of the modules described. Execution class lookup, which can load the scope of the black-and-white list module configuration class, reduce class search time and speed up startup.
【技术实现步骤摘要】
一种web容器中的模块加载方法和装置
本专利技术涉及计算机
,尤其涉及一种web容器中的模块加载方法和装置。
技术介绍
当今互联网上充斥着无数的web网站,每一个Web网站就是一个Web应用,而每个应用都会部署在一个web容器上。Web容器实际上就是一个Java运行时(Runtime)环境,提供了应用的类加载(classloader)、JavaServletAPI的初始化及发布,并提供基于超文本传输协议(HyperTextTransferProtocol,HTTP)/安全套接字层超文本传输协议(HyperTextTransferProtocoloverSecureSocketLayer,HTTPS)的一系列访问接口。Web容器是一个基础的类(class)运行环境,每一段Java程序都会以.class形式发布,并归档在一系列jar、war、sar类型的软件包中。Web容器在启动时需要使用各自的类加载器,从自定义的类查找目录下查找需要的class文件及资源文件,经过class装载、链接、初始化后,Java虚拟机(JavaVirtualMachine,JVM)中将 ...
【技术保护点】
1.一种web容器中的模块加载方法,其特征在于,包括:在第一web应用的web容器启动过程中,获取预先配置的所述第一web应用的各模块的黑名单和/或白名单;若获取到所述第一web应用的各模块的白名单,当通过通用类加载器查找类时,在所述白名单中包括的各模块中执行类查找和加载;若获取到所述第一web应用的各模块的黑名单、且未获取到所述第一web应用的各模块的白名单,当通过通用类加载器查找类时,遍历对应的通用类加载路径下的各个模块是否包括在所述黑名单中,若对应的通用类加载路径下的任一模块包括在所述黑名单中,则不针对所述任一模块执行类查找。
【技术特征摘要】
1.一种web容器中的模块加载方法,其特征在于,包括:在第一web应用的web容器启动过程中,获取预先配置的所述第一web应用的各模块的黑名单和/或白名单;若获取到所述第一web应用的各模块的白名单,当通过通用类加载器查找类时,在所述白名单中包括的各模块中执行类查找和加载;若获取到所述第一web应用的各模块的黑名单、且未获取到所述第一web应用的各模块的白名单,当通过通用类加载器查找类时,遍历对应的通用类加载路径下的各个模块是否包括在所述黑名单中,若对应的通用类加载路径下的任一模块包括在所述黑名单中,则不针对所述任一模块执行类查找。2.如权利要求1所述的方法,其特征在于,所述方法还包括:在第一web应用的web容器启动过程中,在初始化类加载路径之后,执行类冲突检测得到检测结果,并给出日志提示。3.如权利要求2所述的方法,其特征在于,所述类冲突检测包括jar包的多版本检测和类的依赖检测。4.如权利要求3所述的方法,其特征在于,执行类冲突检测得到检测结果,并给出日志提示,包括:遍历所述通用类加载路径下的所有jar包,识别名称相同的jar包和名称相同且版本不同的jar包,得到检测结果,并给日志提示;对通用类加载路径下的所有类文件进行字码解析,获取类依赖关系,并从所述通用类加载路径下查找所述依赖关系否存在,得到检测结果,并给出日志提示。5.如权利要求1-4任一项所述的方法,其特征在于,所述方法还包括:若对应的通用类加载路径下的任一模块不包括在所述黑名单中,则针对所述任一模块执行类查找和加载。6.一种web容器中的模块加载装置,其特征在...
【专利技术属性】
技术研发人员:赵斌,汪辉,张良发,周俊杰,
申请(专利权)人:华为软件技术有限公司,
类型:发明
国别省市:江苏,32
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。