
1、smart-servlet 简介
smart-servlet 是目前 Gitee、Github 平台上首款,也是 唯一的全栈核心技术自研 的国产开源的 Servlet 容器项目。
产品特色
-
国产血统:核心技术 100% 全栈自研。
-
性能优越:搭载最新版通信微内核 smart-socket。
-
安全可靠:严格遵循协议规范;支持加密传输方式。
-
极致轻量:发行包不足 800KB。
-
简洁易用:支持 War 包、springboot、maven-plugin 等多种运行模式,使用体验 100% 兼容 Tomcat。
版本比较
| 功能 | 开源版 | 企业版 |
|---|---|---|
| 目标用户 | 个人 | 企业 |
| Servlet基础能力 | ✅ | ✅ |
| Websocket规范 | ✅ | ✅ |
| 异步规范 | ✅ | ✅ |
| Session并发实例化 | 1个/秒 | 无限制 |
| 会话安全性 | 弱 | 强 |
| War包部署 | ❌ | ✅ |
| JSP | ❌ | ❌ |
2、 版本更新
smart-servlet 的这个版本着重提升 TCK 用例的覆盖度。
已将用例数从 360 个,提升至如今的 665 个。而随着用例通过数的增长,使得 smart-servlet 在规范细节上的实现更加成熟。
另外,这个版本我们决定将原先企业版的功能(WebSocket、异步规范)也进行开源。降低用户对于 smart-servlet 采取商业不友好开源模式(AGPL开源协议)的顾虑,同时也让用户更加全面的了解 smart-servlet。
自此,smart-servlet 开源代码量接近 1.7 万行,闭源代码量仅剩 700 行左右,开源比例高达 96%。倘若后续积攒了足够体量的用户(尊重开源成果的用户,不包括白嫖),smart-servlet 将开放所有源码。
前段时间将最新的 smart-servlet 提交了 tfb 评测,从结果来看smart-servlet 在性能方面较 undertow 依旧呈碾压之势。
更新内容
-
优化 Servlet 初始化机制,防止多次执行
init -
优化
ServletRegistration#addMapping规范实现。 -
优化
HttpServletRequest#getIntHeader规范实现。 -
优化
HttpServletRequest#getSession规范实现。 -
优化
HttpServletRequest#setCharacterEncoding规范实现 -
优化
HttpServletRequest#getReader规范实现 -
优化
ServletContext#getResource规范实现 -
优化
ServletContext#getRealPath规范实现 -
优化
ServletContext#setInitParameter规范实现 -
优化
ServletContext#addServlet规范实现 -
优化
ServletContext#createServlet规范实现 -
优化
ServletContext#getServletRegistration规范实现 -
优化
ServletContext#getServletRegistrations规范实现 -
优化
ServletContext#addFilter规范实现 -
优化
ServletContext#getFilterRegistration规范实现 -
优化
ServletContext#getSessionCookieConfig规范实现 -
优化
ServletContext#getFilterRegistrations规范实现 -
优化
ServletContext#setSessionTrackingModes规范实现 -
优化
ServletContext#addListener规范实现 -
优化
ServletContext#createListener规范实现 -
新增
HttpServletRequest#getPathTranslated规范实现。 -
开源企业版插件:
AsyncContextPlugin -
开源企业版插件:
WebsocketPlugin
3、快速上手
我们提供了三种方式启用 smart-servlet,您可根据实际情况选择其中适用的一种。
方式一:maven 插件
这是一种类似:tomcat-maven-plugin 的使用方式,通常应用于 Java Web 工程的本地开发环境。集成该插件只需在 pom.xml 中加入以下代码,便可以在 IDE 中启动 servlet 服务。
<build> <plugins> <plugin> <groupId>org.smartboot.servlet</groupId> <artifactId>smart-servlet-maven-plugin</artifactId> <version>{最新版}</version> <configuration> <port>8080</port> <path>/portal</path> </configuration> </plugin> </plugins> </build> 插件的版本建议采用最新版本,另外主要的配置项包括:
-
port:servlet 服务启动的监听端口
-
path:Servlet 容器上下文路径,即 ContextPath,通常以 / 表示。当然也支持自定义,但必须以 / 开头 完成配置后在控制台输入:
mvn package smart-servlet:run即可。
方式二:smart-servlet-spring-boot-starter
用过 springboot 的 spring-boot-starter-tomcat 或者 spring-boot-starter-undertow 的朋友应该对此不陌生。
smart-servlet-spring-boot-starter 本质上就是 smart-servlet 对 spring-boot-starter-web 的另一种适配。
只需按照以下方式调整 springboot 工程中 pom.xml 文件的配置,便可将 springboot 的默认 Servlet 容器替换成 smart-servlet。
<dependencys> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <!-- Exclude the Tomcat dependency --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- Use smart-servlet instead --> <dependency> <groupId>org.smartboot.servlet</groupId> <artifactId>smart-servlet-spring-boot-starter</artifactId> <version>{最新版}</version> </dependency> </dependencys> 方式三:发行包
发行包适用于 War 包的部署方式,也是生产环境中常用的一种形式。(联系作者获取)






