Scala + Spring Boot (Actuator RESTful API)


build.sbt

import sbt.internal.IvyConsole.Dependencies._

lazy val springVersion = "1.5.3.RELEASE"
lazy val thymeleafVersion = "2.1.5.RELEASE"

lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "org.bk",
scalaVersion := "2.11.0",
version := "1.0"
)),
name := "immosis-scheduler-immobilienscout24",
libraryDependencies += "org.springframework.boot" % "spring-boot-starter-web" % springVersion,
libraryDependencies += "org.springframework.boot" % "spring-boot-starter-actuator" % springVersion
)
mainClass in (Compile, run) := Some("HelloWorldApplication")

HelloWorldApplication.scala

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

object HelloWorldApplication extends App {
SpringApplication.run(classOf[HelloWorldApplication]);
}

@SpringBootApplication
class HelloWorldApplication

HelloWorldController.scala

import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{GetMapping, RequestParam, ResponseBody}

@Controller
class HelloWorldController {

@GetMapping(Array("/hello-world"))
@ResponseBody
def sayHello(@RequestParam(name="name", required=false, defaultValue="Stranger") name: String): Greeting = {
new Greeting("Hello, "+name)
}
}

Greeting.scala
class Greeting(content: String){
def getContent():String = content
}

sbt run

curl localhost:8080/hello-world
{"content":"Hello, Stranger"}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s