Router issues with Vertx

Viewed 9178

Good morning, I begin with Vertx for java and I want to create the route example so I copy past the lines but it seems there is something wrong in Router.router(vertex) :

  • The type io.vertx.rxjava.core.Vertx cannot be resolved. It is indirectly referenced from required .class files

    • The method router(Vertx) from the type Router refers to the missing type Vertx

Here is my code :

import io.vertx.core.*;
import io.vertx.rxjava.ext.web.*;
import io.vertx.core.http.HttpHeaders;

public class Test extends AbstractVerticle{

@Override
public void start() throws Exception {

    Vertx vertx=Vertx.vertx();
    Router router = Router.router(vertx);

    Route route1 = router.route("localhost:8080/Orsys/").handler(routingContext -> {

          HttpServerResponse response = routingContext.response();
          response.setChunked(true);

          response.write("Orsys\n");

          routingContext.vertx().setTimer(5000, tid -> routingContext.next());
        });
2 Answers

Eric Zhao's answer is great. But I want to add something.

I faced to the same issue with my Vert.x application. It first said Cannot resolve symbol 'Router'. So I import io.vertx.ext.web.Router. But my application didn't import it and said Cannot resolve symbol 'web' and also Cannot resolve symbol 'Router'.

I solved that issue by adding below dependency to my pom.xml .

Maven

<dependency>
 <groupId>io.vertx</groupId>
 <artifactId>vertx-web</artifactId>
 <version>3.6.2</version>
</dependency>

Gradle

dependencies {
 compile 'io.vertx:vertx-web:3.6.2'
}
Related