Creating and Deploying a RESTful Web Service with Spring Boot

Hello,

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.

Application.kt

import com.example.blog.conectores.MySQLDatabaseExampleKotlin
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class Application

fun main(args: Array<String>) {

    //Arrancar Webservice
    SpringApplication.run(Application::class.java, *args)
}

ProfileController.kt

import com.example.blog.Greeting
import com.example.blog.Profile
import com.example.blog.ProfileID
import com.example.blog.conectores.MySQLDatabaseExampleKotlin
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

@RestController
class ProfileController {
    val counter = AtomicLong()

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


    @GetMapping("/profile")
    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{
        MySQLDatabaseExampleKotlin.getConnection()
        id_usuario  = MySQLDatabaseExampleKotlin.executeMySQLQuery("user_id", "bdapptest.tb_users", "name = \"$name\"")
        return id_usuario
    }
}

Cap1

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

Cap2

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 SpringApplication.run(), like the quoted code.

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