【发布时间】:2019-03-11 20:58:03
【问题描述】:
我正在尝试使用 Payara Micro (5.191) 和 xsbt-web-plugin (4.0.2) 设置服务。
build.sbt:
ThisBuild / organization := "local.test"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.12.8"
lazy val testService = project
.enablePlugins(ContainerPlugin)
.settings(
javaOptions in Container ++= Seq("-Xdebug", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"),
libraryDependencies ++= Seq(
microprofile,
servlet
),
containerLibs in Container := Seq(
"fish.payara.extras" % "payara-micro" % "5.191"
),
containerLaunchCmd in Container := { (port, path) =>
Seq("fish.payara.micro.PayaraMicro")
}
)
lazy val microprofile = {
sys.props += "packaging.type" -> "jar"
"org.eclipse.microprofile" % "microprofile" % "2.2" % "provided" pomOnly()
}
lazy val servlet = "javax.servlet" % "javax.servlet-api" % "4.0.1" % "provided"
Main.scala:
package local.test
import java.util
import javax.ws.rs.ApplicationPath
import javax.ws.rs.core.Application
import local.test.endpoint.Hello
@ApplicationPath("/*")
class Main extends Application {
override def getClasses: util.Set[Class[_]] = {
val h = new util.HashSet[Class[_]]
h.add(classOf[Hello])
h
}
}
Hello.scala:
package local.test.endpoint
import javax.ws.rs.core.{MediaType,Response}
import javax.ws.rs.{GET, Path, Produces, QueryParam}
@Path("/hello")
class Hello {
@GET
@Produces(Array(MediaType.TEXT_PLAIN))
def getMessage(@QueryParam("name") name: String): Response = {
Response.ok("Hallo " + name).build
}
@GET
@Produces(Array(MediaType.TEXT_PLAIN))
def getMessage: Response = {
Response.ok("Hallo Nobody").build
}
}
服务器启动并没有显示错误,但我无法打开网站。
1) http://localhost:8080/test 是正确的网址吗?
2) 如何检查此应用程序是否已部署?
3) 我错过了什么?
【问题讨论】:
-
Payara Micro 如何知道要提供哪些课程?是否需要将
local.test.Main指定为入口点的配置文件、JVM 属性或类似文件? -
据我所知,应该是通过
Main类的javax.ws.rs.ApplicationPath接口。使用getClasses函数可以找到端点。 -
它怎么知道
main类是local.test.Main?它会扫描所有main类的类路径,还是有办法配置它? -
我认为关键是
--deploy参数。有了这个,我能够让 Payara Micro 找到并尝试启动该服务,但由于注释中出现的问题而失败。尝试将您的containerLaunchCmd更改为Seq("fish.payara.micro.PayaraMicro", "--deploy", "testService/target/webapp"),看看是否可以重现。 -
我能够通过两个更改让它工作。 1. 添加
--deploy,如上述评论中所述。 2.从Hello中删除getMessage方法之一
标签: payara xsbt-web-plugin payara-micro