vert.x框架-简单路由使用
2024-10-19 17:36:53
package xue.myVertX; import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.ext.web.Router; /**
* 简单的路由使用
*/
public class SimpleRouter extends AbstractVerticle {
@Override
public void start() throws Exception {
// 创建HttpServer
HttpServer server = vertx.createHttpServer();
// 创建路由对象
Router router = Router.router(vertx);
// 监听/index地址
router.route("/index").handler(request -> {
request.response().end("INDEX SUCCESS");
});
// 把请求交给路由处理--------------------(1)
server.requestHandler(router::accept);
server.listen(8888);
} public static void main(String[] args) {
Vertx.vertx().deployVerticle(new SimpleRouter());
}
}
1.
注意,Router包导入不要导错了,应该
import io.vertx.ext.web.Router;
否则会提示
2.
需要提前在maven导入依赖,当前使用版本
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>3.5.2</version>
</dependency>
更多版本在这里:https://mvnrepository.com/artifact/io.vertx/vertx-web
虽然只是导入了vertx-web,但是会下载很多东西,这些都是
最新文章
- 10道javascript笔试题
- swift基础语法(四) 函数、闭包(Closures)
- 创建 maven 本地仓库
- .NET学习记录2
- Phaser开源2d引擎 html5游戏框架中文简介
- lnmp一键安装包删除添加的域名
- 如何修改HDFS的备份数
- linux input输入子系统应用分析
- spring 解析配置文件问题
- C# 创建线程的简单方式:异步委托 .
- 时间格式nls_date_format的设置
- Jenkins中关于一些插件的使用方法
- 生成UUID简易版
- Spring Security(十一):4. Samples and Guides (Start Here)
- android checkBox选中与取消
- Zookeeper系列2 原生API 以及核心特性watcher
- 数据结构:IO读写频繁的青睐,B树和B+树
- Redis学习---Redis操作之List
- Unity面试问题归总
- 【转载】IDEA:放置型塔防备忘录
热门文章
- 图形学之Unity渲染管线流程
- useEffect无限调用问题
- 关于thinkPHP中的自动加载和手动导入
- A New Discrete Particle Swarm Optimization Algorithm
- grep的时候Binary file matches **.log 怎么解决
- Shell之awk常用用法
- xml数据结构处理
- 【LeetCode】845. Longest Mountain in Array 解题报告(Python)
- 1076 - Get the Containers
- bootstrap datetimepick 时分秒选择,坑我15个小时,整理记录