-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.kt
34 lines (31 loc) · 1.18 KB
/
main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import org.eclipse.jetty.server.*
import org.eclipse.jetty.servlet.*
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*
import org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext
import org.springframework.web.servlet.DispatcherServlet
import java.util.concurrent.CompletableFuture
@Controller("/")
open class Page {
@GetMapping("/page1")
open fun page1(str: String) = CompletableFuture.completedFuture("forward:/page2")
@GetMapping("/page2")
@ResponseBody
open fun page2(str: String) = "params: $str"
}
fun main() {
Server().apply {
insertHandler(ServletContextHandler().apply {
val ctx = AnnotationConfigWebApplicationContext().apply {
register(Page::class.java)
refresh()
}
addServlet(ServletHolder(DispatcherServlet(ctx)), "/")
servletContext.setAttribute(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx)
})
addConnector(ServerConnector(server).apply { port = 8070 })
start()
join()
}
}