我是靠谱客的博主 落后西牛,这篇文章主要介绍idea tomcat启动servlet容器篇-SPImvcBootDemo,现在分享给大家,希望可以做个参考。

mvcBootDemo

分支介绍

master

基本的启动servlet mvc

spi

通过spi,无web.xml启动servlet,实现手动注册servlet的功能。

spi 分支步骤

1.去掉webapp 目录

2.resources 增加文件

文件路径:resources/META-INF/services/javax.servlet.ServletContainerInitializer
文件内容

com.demo.Initializer.DemoServletContainerInitializer

3.DemoServletContainerInitializer

注意 handlesType

Because this class declares @HandlesTypes(WebApplicationInitializer.class), Servlet 3.0+ containers will automatically scan the classpath for implementations of Spring’s WebApplicationInitializer interface and provide the set of all such types to the webAppInitializerClasses parameter of this method.

@HandlesTypes(IDemoApplicationInitializer.class)
public class DemoServletContainerInitializer implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        。。。。
    }
}

4.IDemoApplicationInitializer 的实现类

public class DemoServletInitializer implements IDemoApplicationInitializer {
    @Override
    public void init(ServletContext servletContext) throws ServletException {
        //添加servlet
        ServletRegistration.Dynamic demoServlet = servletContext.addServlet("demoServlet", DemoServlet.class);
        demoServlet.addMapping("/*");
    }
}

代码路径

https://gitee.com/whiteubuntu/mvc-boot-demo

学习

https://blog.csdn.net/gaohaicheng123/article/details/105827295

最后

以上就是落后西牛最近收集整理的关于idea tomcat启动servlet容器篇-SPImvcBootDemo的全部内容,更多相关idea内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(278)

评论列表共有 0 条评论

立即
投稿
返回
顶部