Big projects are handed over to Spring, and small projects can try Magician
Magician is a small HTTP service package developed based on Netty. It is very convenient to start an http service. It also supports WebSocket and annotation Handler configuration.
operating environment
JDK11+
The Jar package of the central library supports JDK11 at least, but the source code can support jdk8 at least. If you need to run on 8, you can download the latest tag and compile it yourself
document
example
import dependencies
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician</artifactId>
<version>2.0</version>
</dependency>
<!-- 这是日志包,必须有,不然控制台看不到东西,支持任意可以看slf4j桥接的日志包 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.12</version>
</dependency>
create http service
Create a Handler
@HttpHandler(path="/")
public class DemoHandler implements HttpBaseHandler {
@Override
public void request(MagicianRequest magicianRequest, MagicianResponse response) {
// response data
magicianRequest.getResponse()
.sendJson(200, "{'status':'ok'}");
}
}
create http service
Magician.createHttp()
.scan("handler所在的包名")
.bind(8080);
Create WebSocket
@WebSocketHandler(path = "/websocket")
public class DemoSocketHandler implements WebSocketBaseHandler {
@Override
public void onOpen(WebSocketSession webSocketSession) {
}
@Override
public void onClose(WebSocketSession webSocketSession) {
}
@Override
public void onMessage(String message, WebSocketSession webSocketSession) {
}
}
more components
These components can be used to easily develop web projects