Jetty error: HTTP method GET is not supported by this URL

Jetty error: HTTP method GET is not supported by this URL

我正在使用 HTTP4S 并且 webapp 在码头上 运行。 Web 应用程序文件配置为:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">


   <servlet>
      <servlet-name>user-svc</servlet-name>
      <servlet-class>io.databaker.UserSvcServlet</servlet-class>
      <async-supported>true</async-supported>
   </servlet>

   <servlet-mapping>
      <servlet-name>user-svc</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>

</web-app>

可用的 URI 是:

object UserSvcRoutes {

  def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = {
    val dsl = new Http4sDsl[F]{}
    import dsl._
    HttpRoutes.of[F] {
      case GET -> Root =>
        Ok("Example")
      case GET -> Root / "hello" / name =>
        for {
          greeting <- H.hello(HelloWorld.Name(name))
          resp <- Ok(greeting)
        } yield resp
    }
  }

}

当我调用 http://localhost:8080/ 时,我得到:

我做错了什么?

Http4sServlet was recently made abstract, with two concrete implementations provided by BlockingHttp4sServlet and AsyncHttp4sServlet.

您可以通过更改 UserSvcServlet 来扩展以下任一方法来使您的示例正常工作:

package io.databaker

import AppContextShift._
import cats.effect._
import java.util.concurrent.Executors
import org.http4s.server.DefaultServiceErrorHandler
import org.http4s.servlet.BlockingHttp4sServlet
import org.http4s.servlet.BlockingServletIo

class UserSvcServlet
  extends BlockingHttp4sServlet[IO](
    service = UserSvcServer.start,
    servletIo = BlockingServletIo(4096, Blocker.liftExecutorService(Executors.newCachedThreadPool())),
    serviceErrorHandler = DefaultServiceErrorHandler
  )