您的位置:首页 > 运维架构 > Tomcat

Tomcat源码阅读-为什么Bootstrap反射调用Catalina?

2018-02-13 17:15 633 查看

RT

看Bootstrap类注释上写的很清楚

/**
* 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
*/
public final class Bootstrap {


为了把Catalina及它依赖的类比如 XML parser与应用级别的类隔离(以使用不同类加载器的方法)

确认加载正确的Catalina类,因为tomcat也有三个类加载器,双亲委派模型,https://q.cnblogs.com/q/91104/

tomcat的启动是通过bootstrap 加载一些公共类、配置环境、实例化Catalina类,具体的业务代码还是在catalina类里面的。这样反射的好处是解耦。 可以不依赖应用层的classpath独立加载,通过catalina.home指定相应的目录就可以了,对应用程序不可见 https://www.cnblogs.com/qichengXiao/p/5897687.html

还有别的原因吗?欢迎补充

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: