scalatra_LifeCycle

scalatra是如何启动的

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

class ScalatraListener extends ServletContextListener {

import org.scalatra.servlet.ScalatraListener._

private[this] val logger: Logger = Logger[this.type]

private[this] var cycle: LifeCycle = _

private[this] var servletContext: ServletContext = _

override def contextInitialized(sce: ServletContextEvent): Unit = {

try {
//contextInitialized 后赋值给servletContext
configureServletContext(sce)
configureCycleClass(Thread.currentThread.getContextClassLoader)
} catch {
case e: Throwable =>
logger.error("Failed to initialize scalatra application at " + sce.getServletContext.getContextPath, e)
throw e
}
}

def contextDestroyed(sce: ServletContextEvent): Unit = {
if (cycle != null) {
logger.info("Destroying life cycle class: %s".format(cycle.getClass.getName))
cycle.destroy(servletContext)
}
}

protected def configureExecutionContext(sce: ServletContextEvent): Unit = {
}

//寻找LifeCycle
protected def probeForCycleClass(classLoader: ClassLoader): (String, LifeCycle) = {

}

protected def configureServletContext(sce: ServletContextEvent): Unit = {
//定义servletContext 从sce获取
servletContext = sce.getServletContext
}

protected def configureCycleClass(classLoader: ClassLoader): Unit = {

}
}

object ScalatraListener {

// DO NOT RENAME THIS CLASS NAME AS IT BREAKS THE ENTIRE WORLD
// TOGETHER WITH THE WORLD IT WILL BREAK ALL EXISTING SCALATRA APPS
// RENAMING THIS CLASS WILL RESULT IN GETTING SHOT, IF YOU SURVIVE YOU WILL BE SHOT AGAIN
val DefaultLifeCycle: String = "ScalatraBootstrap"
val OldDefaultLifeCycle: String = "Scalatra"
val LifeCycleKey: String = "org.scalatra.LifeCycle"

}
欢迎关注我的公众号:沉迷Spring
显示 Gitment 评论
0%