Vert.x整合springboot

1.添加maven中的依赖

<!--spring-boot依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--vertx依赖-->
<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-core</artifactId>
    <version>3.7.1</version>
</dependency>
<dependency>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-web</artifactId>
    <version>3.2.1</version>
</dependency>

2.编辑Vert.x配置文件

@Configuration
public class VertxConfiguration {
    @Autowired
    Environment environment;

    public int httpPort() {
        return environment.getProperty("http.port", Integer.class, 8888);
    }
}

3.编辑Vert.x启动文件

@Component
public class Server extends AbstractVerticle {
   @Autowired
    VertxConfiguration configuration;

   @Override
   public void start() throws Exception {
      vertx.createHttpServer().requestHandler(router::accept).listen(configuration.httpPort());
   }

4.让springboot自动启动Vert.x

@SpringBootApplication
public class UStreetAppJavaApplication {
    @Autowired
    private Server server;

    public static void main(String[] args) {
        SpringApplication.run(UStreetAppJavaApplication.class,args);
    }
    @PostConstruct
    public void deployVerticle() {
        Vertx.vertx().deployVerticle(server);
    }
}

注释:VertxConfiguration中的端口与application.yml中配置的端口是俩个不一样的东西

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值