几个java轻量级web服务框架
平时偶尔写一些小程序或者小工具小服务,使用springboot
都觉得比较重量级,就找了找比较方便上手的轻量级web
服务框架以备不时之需
比较容易上手的两个框架
sparkjava
Spark - a tiny web framework for Java 8
上手
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-kotlin</artifactId>
<version>1.0.0-alpha</version>
</dependency>
import static spark.Spark.*;
public class HelloWorld {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
}
}
默认启动端口4567
http://localhost:4567/hello
javalin
A simple and modern Java and Kotlin web framework
上手
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.6.0</version>
</dependency>
import io.javalin.Javalin;
public class HelloWorld {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7000);
app.get("/", ctx -> ctx.result("Hello World"));
}
}