springboot中如何实现整合ktor-创新互联

这篇文章将为大家详细讲解有关spring boot中如何实现整合ktor,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联专业为企业提供河南网站建设、河南做网站、河南网站设计、河南网站制作等企业网站建设、网页设计与制作、河南企业网站模板建站服务,10多年河南做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

背景

在用了一阵子 Ktor 之后,深感基于协程的方便,但是公司的主要技术栈是 SpringBoot,虽然已经整合了 Kotlin,但是如果有 Ktor 加持则会更加的方便。因此作了一番研究后,也完全可以实现这样的整合了。

建立一个 starter

首先新建一个 Kotlin 项目,在其 build.gradle 内加入对 SpringBoot 和 Ktor 的依赖,并同时加入对打为 jar 包的代码:

dependencies {
  implementation "org.springframework.boot:spring-boot-starter-aop:${springBootVersion}"
  implementation "io.ktor:ktor-jackson:${ktorVersion}"
  compile "io.ktor:ktor-server-netty:${ktorVersion}"
  compile "io.ktor:ktor-html-builder:${ktorVersion}"

  testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
  testCompile "io.ktor:ktor-client-apache:${ktorVersion}"
  testCompile "io.ktor:ktor-server-test-host:${ktorVersion}"
}

jar {
  from {
    configurations.runtime.collect { zipTree(it) }
  }
}

task sourceJar(type: Jar) {
  from sourceSets.main.allSource
  classifier 'sources'
}

分享文章:springboot中如何实现整合ktor-创新互联
本文地址:http://pwwzsj.com/article/dsphsi.html