我构建了一个使用 Jetty 作为 Servlet 容器的 http4s 网络应用程序。下面的代码显示了服务器的实现:
@WebListener
class Bootstrap extends ServletContextListener with IOApp {
override def contextInitialized(sce: ServletContextEvent): Unit = {
val ctx = sce.getServletContext
val blocker = Blocker.liftExecutionContext(ExecutionContext.global)
ctx.mountService("user-svc", UserSvcRoutes.helloWorldRoutes[IO](HelloWorld.impl[IO]))
()
}
override def contextDestroyed(sce: ServletContextEvent): Unit = {}
override def run(args: List[String]): IO[ExitCode] = ???
}
然后我编译为 WAR 文件并将其放入webapps
主 jetty 文件夹的子文件夹中:
Jetty 服务器启动后,显示:
但我想获取服务的主页:
而不是点击:
进入服务。
在 中WEB-INF
,我创建了jetty-web.xml
具有以下内容的文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC
"-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/user-svc</Set>
</Configure>
并且不起作用。
如何获得user-svc
作为根路径/
?