[go: nahoru, domu]

Skip to content

Invizible/vertx-spring-aware

Repository files navigation

vertx-spring-aware

Allows you to write verticles as a spring components.

You can find examples here.

How to use

Import one of Spring Configuration classes (VertxConfiguration or ClusteredVertxConfiguration) in your Context

@Import(VertxConfiguration.class) // 1. Import Vertx configuration
@SpringBootApplication
public class SpringVertxApplication {

  public static void main(String[] args) {
    SpringApplication.run(SpringVertxApplication.class, args); // 2. Run app (will create Spring context)
  }

}

Put @Verticle annotation on your Verticles:

@Verticle
public class ServerVerticle extends AbstractVerticle {

  @Autowired
  private TestService testService;

  @Override
  public void start() throws Exception {
    HttpServer httpServer = vertx.createHttpServer()
      .requestHandler(request -> {
        request.response().end(testService.getMessage());
      })
      .listen(8080);
  }
}

That's it. Now all your Verticles will be deployed automatically by VertxConfiguration and dependency injection will be available.

See examples project for more use cases.

About

Allows you to write verticles as a spring components

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages