简体   繁体   English

Java EE部署中的Spring Classloading机制

[英]Spring Classloading mechanism in Java EE deployment

I would like to understand how ClassLoader of Spring Container. 我想了解Spring容器的ClassLoader。

Here is an example: Deploy a WAR containing all the necessary jars so that Spring Container is started inside the webcontainer of tomcat. 这是一个示例:部署一个包含所有必要jar的WAR,以便在tomcat的web容器内启动Spring Container。

Questions I have: 我有问题:
1. Am I correct in thinking that Spring container classes itself are loaded by the ClassLoader of WAR created by web-container ? 1.我是否认为Spring容器类本身由web-container创建的WAR的ClassLoader加载是正确的?
2. When the WAR is undeployed, how are the Class [] (java.lang.Class objects) loaded by the spring container unloaded. 2.取消部署WAR时,如何卸载spring容器加载的Class [](java.lang.Class对象)。 Is spring having a classloader to itself ? 春天本身有一个类加载器吗? Or it uses classloader provided by webcontainer ? 还是使用webcontainer提供的类加载器?
3. If my Spring Container is inheriting beans (using parentContextKey in web.xml), and if one of the parent beans has lazy-init=true and is requested by this deployed WAR, who will load and unload the Class object of the requested bean ? 3.如果我的Spring容器继承了bean(使用web.xml中的parentContextKey),并且其中一个父bean具有lazy-init = true且已由部署的WAR请求,则谁将加载和卸载所请求的Class对象豆角,扁豆 ?

Thanks in advance 提前致谢

All these life cycles is maintained by the container and u make it aware by declaring it in web.xml for example 所有这些生命周期都是由容器维护的,例如,您可以通过在web.xml中进行声明来使其醒目

The RequestContextListener exposes the 'request' scope to the context. RequestContextListener将“请求”范围公开给上下文。
org.springframework.web.context.request.RequestContextListener org.springframework.web.context.request.RequestContextListener

And this listener which extends from the container listener, the container is able to handle the lifecycle. 从容器侦听器扩展的这个侦听器,容器能够处理生命周期。

If u have any thing which is lazy init. 如果您有任何东西是惰性的init。 The web container delegates the call to spring container which search for the class in the classpath. Web容器将调用委派给spring容器,该容器在类路径中搜索类。

So essentially the life cycles gets handled. 因此,生命周期得到了处理。 You can also have your own customised listener which handles these life cycles 您还可以拥有自己的自定义侦听器,以处理这些生命周期

see if it helps 看看是否有帮助

Your web-app can be based on Spring or simply on JSP&Servlets. 您的Web应用程序可以基于Spring或仅基于JSP&Servlet。 And when you run Tomcat or other servlet container then it uses its ClassLoader that load classes and libraries from your WAR which is deployed to webapp folder (for Tomcat). 并且当您运行Tomcat或其他servlet容器时,它会使用其ClassLoader从WAR加载类和库,而WAR则将其部署到webapp文件夹(对于Tomcat)中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM