本文整理汇总了Scala中org.glassfish.jersey.servlet.ServletContainer类的典型用法代码示例。如果您正苦于以下问题:Scala ServletContainer类的具体用法?Scala ServletContainer怎么用?Scala ServletContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServletContainer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Server
//设置package包名称以及导入依赖的类
package works.weave.socks.aws.orders.main
import org.eclipse.jetty
import org.eclipse.jetty.servlet.ServletContextHandler
import org.eclipse.jetty.servlet.ServletHolder
import org.glassfish.jersey.servlet.ServletContainer
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import scala.collection.JavaConverters._
import scala.util.control.NonFatal
import Server._
import org.eclipse.jetty.util.log.Slf4jLog
@Component
class Server(val jerseyApp : JerseyApp) {
def run() : Unit = {
jetty.util.log.Log.setLog(new Slf4jLog())
val port = System.getenv().asScala.getOrElse("PORT", "80").toInt
val context = new ServletContextHandler(ServletContextHandler.SESSIONS)
context.setContextPath("/")
val jettyServer = new jetty.server.Server(port)
jettyServer.setHandler(context)
val servletContainer = new ServletContainer(jerseyApp)
val servletHolder = new ServletHolder(servletContainer)
context.addServlet(servletHolder, "/*")
val jerseyServlet = servletHolder
jerseyServlet.setInitOrder(0)
try {
Log.info("Starting jetty")
jettyServer.start()
Log.info("Jetty started")
jettyServer.join()
Log.info("Jetty exited")
} finally {
Log.info("Destroying jetty")
try {
jettyServer.destroy()
} catch {
case NonFatal(e) => Log.error("Error during Jetty shutdown", e)
}
}
}
}
object Server {
val Log = LoggerFactory.getLogger(classOf[Server])
}