Skip to content

Instantly share code, notes, and snippets.

@antonarhipov
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save antonarhipov/4fbf350a6a0cdb06ff86 to your computer and use it in GitHub Desktop.

Select an option

Save antonarhipov/4fbf350a6a0cdb06ff86 to your computer and use it in GitHub Desktop.
Kotlin servlet with CDI bean
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import javax.servlet.annotation.WebServlet as web
import javax.inject.Inject
import javax.enterprise.context.Dependent
web(name = "Hello", value = array("/hello"))
public class HomeController : HttpServlet() {
Inject
var service: HelloService? = null
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
doStuff(resp)
}
private fun doStuff(resp: HttpServletResponse) {
resp.getWriter().write(service!!.message())
}
}
Dependent
public class HelloService() {
fun message(): String {
return "Hello, CDI!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment