springboot-spring源码系列(三)

110 阅读1分钟

springMVC流程,将会以无xml的方式画流程图,毕竟都2020年了不会还有人用xml配置吧!!!

@Override
public void onStartup(javax.servlet.ServletContext servletCxt) throws ServletException {
    AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext();
    ac.register(AppConfig.class);
    ac.refresh();//官网给出的例子中这个地方进行了refresh(),但是个人认为这个地方的refresh()毫无用处,甚至还会出现错误,建议删掉。
    DispatcherServlet servlet = new DispatcherServlet(ac);
    ServletRegistration.Dynamic registration = servletCxt.addServlet("app", servlet);
    registration.setLoadOnStartup(1);
    registration.addMapping("/app/*");
}

该方式实现的原理将会在后续文章中进行详细说明!!