为什么Tomcat使用反射进行Catalina instancilization

时间:2011-10-06 09:29:57

标签: java tomcat reflection

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

1 个答案:

答案 0 :(得分:3)

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