为什么 Tomcat 使用反射来实现 Catalina 实例化

发布于 2024-12-08 14:09:34 字数 92 浏览 0 评论 0原文

阅读Tomcat 7源码,我只是想知道为什么Tomcat实例Catalina并通过反射调用相关方法而不是简单地使用new创建对象并直接调用方法?

Reading the Tomcat 7 source code, I just wonder why Tomcat instance Catalina and invokes the related methods by using reflection instead of simply using new to create the object and calling the method directly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖伴 2024-12-15 14:09:34

答案在 Bootstrap 类的 javadoc 注释中:

/**
 * Bootstrap loader for Catalina.  This application constructs a class loader
 * for use in loading the Catalina internal classes (by accumulating all of the
 * JAR files found in the "server" directory under "catalina.home"), and
 * starts the regular execution of the container.  The purpose of this
 * roundabout approach is to keep the Catalina internal classes (and any
 * other classes they depend on, such as an XML parser) out of the system
 * class path and therefore not visible to application level classes.
 *
 * @author Craig R. McClanahan
 * @author Remy Maucherat
 * @version $Id: Bootstrap.java 1142323 2011-07-02 21:57:12Z markt $
 */

public final class Bootstrap { ... }

The answer is in the javadoc comment of the Bootstrap class:

/**
 * Bootstrap loader for Catalina.  This application constructs a class loader
 * for use in loading the Catalina internal classes (by accumulating all of the
 * JAR files found in the "server" directory under "catalina.home"), and
 * starts the regular execution of the container.  The purpose of this
 * roundabout approach is to keep the Catalina internal classes (and any
 * other classes they depend on, such as an XML parser) out of the system
 * class path and therefore not visible to application level classes.
 *
 * @author Craig R. McClanahan
 * @author Remy Maucherat
 * @version $Id: Bootstrap.java 1142323 2011-07-02 21:57:12Z markt $
 */

public final class Bootstrap { ... }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文