1、smart-servlet 简介
smart-servlet是目前 Gitee、Github 平台上首款,也是唯一款全栈核心技术自研的国产开源的Servlet容器项目。
产品特色
-
性能优越:搭载最新版通信微内核 smart-socket。
-
安全可靠:严格遵循协议规范;支持加密传输方式。
-
简洁易用:支持 War 包、springboot、maven-plugin等多种运行模式,使用体验100%兼容 Tomcat。
国产血统:核心技术 100% 全栈自研。
模块介绍
模块 | 说明 | 代码量 |
---|---|---|
servlet-core | 实现了Servlet规范的核心模块 | 17000+ |
smart-servlet-maven-plugin | 类似 tomcat-maven-plugin 的 maven 插件 | 100+ |
spring-boot-stater | 适配 springboot 的启动器,类似:spring-boot-starter-tomcat | 100+ |
2、 版本更新
本次更新内容:
-
实现ServletRequestAttributeListener规范
-
实现SessionCookieConfig规范
-
实现HttpServletResponse#setLocale、getLocale规范。
-
实现 WebListener、WebServlet规范
-
支持 Servlet asyncSupported 解析
-
支持web-fragment.xml加载
-
优化HttpServletResponse规范:Cookie、CharacterEncoding、ContentType。
-
优化 Session Cookie。
-
优化ServletPrintWriter
-
优化Servlet URL匹配算法。
-
优化web.xml中url-pattern的解析
-
升级smart-http至1.2.1
-
升级servlet-api至4.0.1
-
升级spring-boot至2.7.11
-
引入servlet tck测试套件
实现HttpSessionAttributeListener规范
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>0.3</version><!--最新版本 --> <configuration> <port>8080</port> <path>/portal</path> </configuration> </plugin> </plugins> </build>
插件的版本建议采用最新版本,另外主要的配置项包括:
-
path:Servlet容器上下文路径,即 ContextPath,通常以/表示。当然也支持自定义,但必须以/开头 完成配置后在控制台输入:mvn package smart-servlet:run即可。
port:servlet服务启动的监听端口
方式二: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>0.3</version><!--最新版本 --> </dependency> </dependencys>
方式三:发行包
发行包适用于 War 包的部署方式,也是生产环境中常用的一种形式。
下载地址:https://gitee.com/smartboot/smart-servlet/releases/
smartboot开源组织,一个容易被误认为是在“重复造轮子”的低调组织。曾获得 2020 年度 OSC 中国开源项目「优秀 Gitee 组织 」荣誉。
该组织内的明星项目包括:
smart-socket
历时5年精炼出2千多行代码,轻松实现百万级长连接的 AIO 通信框架。smart-http
基于 smart-socket 实现的 HTTP/1.1 web服务。smart-servlet
基于 smart-http 实现的 Servlet 3.1/4.0 容器服务。smart-mqtt
基于 smart-socket 实现的 MQTT 3.1.1/5.0 Broker&Client 服务。smart-flow
一款具备可观测性的轻量级业务编排框架。组织地址:https://smartboot.tech/
代码仓库:https://gitee.com/smartboot