springboot源码分析

1、创建servlet三种方式

1)web.xml里面配置

2)@WebServlet   (需要servlet的jar包版本是3.0)

3)容器的api

2、spring官方文档如何实现springmvc,去掉繁琐的xml配置

public class MyWebApplicationInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) {

        // Load Spring web application configuration
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(AppConfig.class);

        // Create and register the DispatcherServlet
        DispatcherServlet servlet = new DispatcherServlet(context);
        ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);
        registration.setLoadOnStartup(1);
        registration.addMapping("/app/*");
    }
}

 

 

posted @ 2021-06-20 11:56  傲云萧雨  阅读(48)  评论(0编辑  收藏  举报