Skip to content

Spring Boot

morfeusys edited this page Mar 31, 2020 · 3 revisions

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". It allows you to serve your JAICF agents as a HTTP servlets.

How to use

This server can be used with any channel that implements HttpBotChannel interface.

Learn more about channels here.

1. Append Spring Boot dependencies to build.gradle

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.3.61"
    kotlin("plugin.spring") version "1.3.61"
    id("org.springframework.boot") version "2.2.2.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
}

tasks.withType<KotlinCompile> {
  kotlinOptions {
    freeCompilerArgs = listOf("-Xjsr305=strict")
    jvmTarget = "1.8"
  }
}

2. Configure and run server

Use HttpBotChannelServlet for HttpBotChannel endpoints.

Here is an example of Amazon Alexa channel configuration:

@Configuration
class Context {

    @WebServlet("/")
    class AlexaController: HttpBotChannelServlet(
        AlexaChannel(helloWorldBot)
    )
}

And then start a server:

fun main(args: Array<String>) {
  runApplication<BlogApplication>(*args) {
    setBannerMode(Banner.Mode.OFF)
  }
}
Clone this wiki locally