Creating and Deploying a RESTful Web Service with Spring Boot



Following this guide, I have managed to create a restfull api with kotlin, and make it work with Intelji, but I can not find the way to deploy it on my Tomcat server, making it completely independent of the programming environment.


import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

class Application

fun main(args: Array<String>) {

    //Arrancar Webservice, *args)


import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import java.util.concurrent.atomic.AtomicLong

class ProfileController {
    val counter = AtomicLong()

    var nombre:String = ""
    var apellidos:String = ""
    var id_usuario:String =""

    fun profile(@RequestParam(value = "id", defaultValue = "0") id: String) =
        //Profile(counter.incrementAndGet(), nombre(id),  id_usuario(id))
        ProfileID(counter.incrementAndGet(), id_usuario(id))

    fun id_usuario(name:String):String{
        id_usuario  = MySQLDatabaseExampleKotlin.executeMySQLQuery("user_id", "bdapptest.tb_users", "name = \"$name\"")
        return id_usuario


Running it from Intellij works correctly, but if I upload the War to Tomcat.


Any idea or thread to throw?

Thank you


Spring Boot is mainly intended for creating standalone applications, which are executed directly and not deployed as a WAR.

If you want traditional WAR deployment of a Spring Boot application, then your Application class should extend SpringBootServletInitializer.


Extending SpringBootServletInitializer is one way, but it’s not the only one. (Some of our apps don’t.)

It should be enough for the main class to be annotated with @SpringBootApplication and have a main() method which calls, like the quoted code.


As you can see, this example has everything you say, but doesn’t work when i deploy on tomcat