gpt4 book ai didi

java - 为什么Tomcat使用反射进行Catalina实例化

转载 作者:行者123 更新时间:2023-11-28 21:57:06 24 4
gpt4 key购买 nike

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

最佳答案

答案在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 { ... }

关于java - 为什么Tomcat使用反射进行Catalina实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7672466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com