阅读Tomcat 7源代码,我只是想知道为什么Tomcat实例Catalina并使用反射而不是简单地使用new
来创建对象并直接调用方法来调用相关方法?
答案 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 { ... }