{"id":21078191,"url":"https://github.com/mrdrivingduck/vertx-backend-template","last_synced_at":"2026-05-17T00:04:25.940Z","repository":{"id":45149376,"uuid":"204104915","full_name":"mrdrivingduck/vertx-backend-template","owner":"mrdrivingduck","description":"🏎️ Java backend template of Vert.x","archived":false,"fork":false,"pushed_at":"2022-02-20T04:02:33.000Z","size":87,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T04:12:26.375Z","etag":null,"topics":["backend","java","template","vertx"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrdrivingduck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-24T03:49:16.000Z","updated_at":"2022-01-07T05:37:33.000Z","dependencies_parsed_at":"2022-09-24T20:12:13.709Z","dependency_job_id":null,"html_url":"https://github.com/mrdrivingduck/vertx-backend-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/mrdrivingduck/vertx-backend-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdrivingduck%2Fvertx-backend-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdrivingduck%2Fvertx-backend-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdrivingduck%2Fvertx-backend-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdrivingduck%2Fvertx-backend-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrdrivingduck","download_url":"https://codeload.github.com/mrdrivingduck/vertx-backend-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdrivingduck%2Fvertx-backend-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007482,"owners_count":26084313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","java","template","vertx"],"created_at":"2024-11-19T19:39:36.448Z","updated_at":"2025-10-11T14:05:35.808Z","avatar_url":"https://github.com/mrdrivingduck.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Vert.x Backend Template\n\n🏎️ Java backend template of [Vert.x](https://vertx.io/)\n\n[![platform-java17](https://img.shields.io/badge/Java%2017-blue?style=for-the-badge\u0026logo=java)](https://openjdk.java.net/projects/jdk/17/)\n[![vertx-logo](https://img.shields.io/badge/Vert.x-purple?style=for-the-badge\u0026logo=eclipsevertdotx)](https://vertx.io)\n\n\u003e This application was generated using http://start.vertx.io\n\n\u003c/div\u003e\n\n## Build and Run\n\n### Run the Tests\n\n```bash\n./mvnw clean test\n```\n\n### Package the Project\n\n```bash\n./mvnw clean package\n```\n\n### Run the Project\n\nRun the source directly:\n\n```bash\n./mvnw clean compile exec:java\n```\n\nRun executable JAR file:\n\n```bash\njava -jar xxx-\u003cversion\u003e-fat.jar\n```\n\n## Components and How to Extend\n\n### Configuration\n\nMore configurations can be added into [`conf/config.json`](conf/config.json) in JSON format. The key of JSON object is named as `xx.xx.xx.xx` which can be used for categorization.\n\nThe configuration will be loaded by **LauncherVerticle** and passed as parameter to **MainVerticle**. Then, MainVerticle is able to get configuration object by `AbstractVerticle.config()`.\n\nThe configuration component is implemented by [Vert.x Config](https://vertx.io/docs/vertx-config/java/), which supports **listening to configuration changes** and **runtime hot-reloading**. Once the backend detects modification of the configuration file, it will undeploy the current MainVerticle and deploy another MainVerticle based on the new configuration.\n\n### Logger\n\n[Apache Log4J 2](https://logging.apache.org/log4j/2.x/) is used as logging backend in this template. The [initialization code](src/main/java/cn/iot/zjt/backend/component/LoggerInitializer.java) follows [Vert.x Core's suggestions](https://vertx.io/docs/vertx-core/java/#_logging) and completes the connection between Vert.x and Log4J2. The configuration file of logger is placed as [`log4j2.xml`](src/main/resources/log4j2.xml) under resource path and is free to customize. The usage of logger is to declare a Logger in each class and free to log anything:\n\n```java\nimport org.apache.logging.log4j.LogManager;\nimport org.apache.logging.log4j.Logger;\n\nprivate static final Logger logger = LogManager.getLogger(Foo.class);\n\nlogger.info(\"Hello world!\");\n```\n\n### Web\n\n[Vert.x Web](https://vertx.io/docs/vertx-web/java/) is used to implement web component. All of the handler functions should be registered to a **Vert.x Web Router**, and the router will be bind to a **Vert.x HTTP Server**. The [initialization code](src/main/java/cn/iot/zjt/backend/component/WebServer.java) loads server configurations like listening port from configuration (`conf/config.json`), and initialize the web router. Finally, it starts the server with the web router and server configurations.\n\n**HTTPS** is supported by a HTTP server option. If enabled, the file path of public key certificate and private key should be provided in the configuration file.\n\nFor handling HTTP requests, the template defines the [`EndPoint`](src/main/java/cn/iot/zjt/backend/handler/annotation/EndPoint.java) annotation to configure each API end point handler. The end point information includes:\n\n- URL path of the end point\n- End point version\n- HTTP request type to access the end point\n- Whether accessing this end point needs authentication\n- Whether handler function needs to execute blocking function (because we cannot block Vert.x's eventloop)\n\nThe **AbstractHandler** is defined to handle the common logic like end point initialization. When extending a new handler, just write a class which extends **AbstractHandler** class and override `handle()` function. Remember to configure end point information with `EndPoint` annotation:\n\n```java\n@EndPoint(\n  path = \"/status\",\n  version = \"0.0.1\",\n  methods = {\"GET\", \"POST\"},\n  jwtAuth = false,\n  block = false\n)\npublic class StatusHandler extends AbstractHttpHandler {\n\n  @Override\n  protected void handle(RoutingContext ctx) {\n    endRequestWithMessage(ctx, 200, \"API status ok.\");\n  }\n}\n```\n\n### JWT Authentication\n\nJSON Web Token authentication is supported with the help of [Vert.x JWT Auth Provider](https://vertx.io/docs/vertx-auth-jwt/java/). A JWT provider instance is initialized with file path of public key certificate and private key, which can be configured in `conf/config.json`. Then, the provider instance can be used **globally** for generating or verifying tokens:\n\n```java\npublic static JWTAuth tokenProvider;\n\npublic static String generateToken(JsonObject param) {\n  return tokenProvider.generateToken(param,\n    new JWTOptions()\n      .setAlgorithm(\"RS256\")\n      .setExpiresInMinutes(60)\n  );\n}\n\npublic static Future\u003cUser\u003e authenticate(String token) {\n  return tokenProvider.authenticate(\n    new JsonObject().put(\"token\", token)\n  );\n}\n```\n\nVert.x provides more authentication methods like OAuth2. Extension can be done in a similar way like JWT.\n\n### Database Connection\n\nCurrently, only MySQL client is supported with the help of [Vert.x MySQL Client](https://vertx.io/docs/vertx-mysql-client/java/). The instance of MySQL client is initialized when the backend starts up, with **connect options** and **pool options** of MySQL server from `conf/config.json`. Then, the MySQL client can be used **globally** for queries, as well as transactions.\n\n```java\n/* instance */\npublic static MySQLPool mysqlClient;\n\n/* configurations */\nMySQLConnectOptions connectOptions = new MySQLConnectOptions()\n  .setHost          (config.getString (\"mysql.host\"))\n  .setPort          (config.getInteger(\"mysql.port\"))\n  .setUser          (config.getString (\"mysql.user\"))\n  .setPassword      (config.getString (\"mysql.password\"))\n  .setDatabase      (config.getString (\"mysql.db\"))\n  .setConnectTimeout(config.getInteger(\"mysql.timeout.second\") * 1000);\nPoolOptions poolOptions = new PoolOptions()\n  .setMaxSize(config.getInteger(\"mysql.pool.size\"));\n\n/* initialization */\nmysqlClient = MySQLPool.pool(vertx, connectOptions, poolOptions);\n\n/* query */\nmysqlClient\n  .query(\"SELECT COUNT(*) FROM table;\")\n  .execute()\n  .compose(rows -\u003e {\n    logQueryRowCount(rows);\n    return Future.succeededFuture();\n  });\n```\n\nMore DBMS clients can be extended in a similar way, as long as Vert.x supports: [PostgreSQL](https://vertx.io/docs/vertx-pg-client/java/), [MongoDB](https://vertx.io/docs/vertx-mongo-client/java/), [Redis](https://vertx.io/docs/vertx-redis-client/java/), [DB2](https://vertx.io/docs/vertx-db2-client/java/), ...\n\n## License\n\nCopyright © 2021 Jingtang Zhang ([Apache License 2.0](LICENSE))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdrivingduck%2Fvertx-backend-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdrivingduck%2Fvertx-backend-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdrivingduck%2Fvertx-backend-template/lists"}