玩转子项目路线
Play with subprojects routes
我有戏! 2.5.3 project with one subproject(有自己的路线)。在主路由文件中,子项目的路由定义如下:
-> /api api.Routes
GET /assets/*file controllers.Assets.at(path="/public", file)
和api.routes
文件如下:
GET /v1/permissions/roles controllers.api.PermissionsController.roles
因此获得角色的 URL 将是 /api/v1/permissions/roles
。
当我 运行 根项目(依赖于两个子项目)时一切正常,但是当 运行 分别连接每个子项目时,找不到路由。我尝试在构建过程中将主路由文件复制到已构建子项目的 conf
文件夹中,但是没有用。
我找到的唯一解决方案是在 application.conf
中添加 play.http.router = "api.Routes"
,但是路由 "looses" 它的 /api
前缀(即:api 路由是/v1/permissions/roles
)
所以我的问题是:是否可以有一个带有路由的子项目,并且这些路由在 运行 根项目和每个 运行 时是相同的子项目分开?
如果可能的话,它在文档中的任何地方吗?
编辑:
build.sbt
用于根项目
name := """abc"""
version := "0.1.0"
scalaVersion := "2.11.7"
resolvers += Resolver.jcenterRepo
javaOptions in Test += "-Dconfig.file=conf/test.conf"
javaOptions in Test += "-Dtest.timeout=600000"
lazy val abcCore = (project in file("modules/abc-core")).enablePlugins(PlayJava, PlayEbean)
lazy val abcCentral = (project in file("modules/abc-central")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore)
.aggregate(abcCore)
lazy val abcSimulador = (project in file("modules/abc-simulador")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore)
.aggregate(abcCore)
lazy val abcDevice = (project in file("modules/abc-device")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore)
.aggregate(abcCore)
lazy val abcApi = (project in file("modules/abc-api")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore, abcSimulador)
.aggregate(abcCore, abcSimulador)
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore, abcDevice, abcCentral, abcSimulador, abcApi)
.aggregate(abcCore, abcDevice, abcCentral, abcSimulador, abcApi)
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"uk.co.panaxiom" %% "play-jongo" % "2.0.0-jongo1.3",
"be.objectify" %% "deadbolt-java" % "2.5.0",
"mysql" % "mysql-connector-java" % "5.1.36",
"org.hibernate" % "hibernate-validator" % "5.2.4.Final",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.5",
"uk.co.modular-it" % "bean-utils" % "0.9.10",
"org.hamcrest" % "hamcrest-library" % "1.3",
"commons-beanutils" % "commons-beanutils" % "1.9.2",
"net.coobird" % "thumbnailator" % "0.4.8",
"io.moquette" % "moquette-broker" % "0.8.1" exclude("org.slf4j", "slf4j-log4j12"),
"org.mindrot" % "jbcrypt" % "0.3m",
"org.apache.commons" % "commons-math3" % "3.6.1",
"com.typesafe.play" %% "play-mailer" % "5.0.0",
"org.thymeleaf" % "thymeleaf" % "3.0.1.RELEASE",
"org.jetbrains.kotlin" % "kotlin-stdlib" % "1.0.3",
"org.eclipse.collections" % "eclipse-collections-api" % "7.1.0",
"org.eclipse.collections" % "eclipse-collections" % "7.1.0",
"org.eclipse.collections" % "eclipse-collections-forkjoin" % "7.1.0",
"net.jpountz.lz4" % "lz4" % "1.3.0",
"org.mapdb" % "elsa" % "3.0.0-M6",
"com.google.guava" % "guava" % "19.0",
"org.jfree" % "jfreesvg" % "3.1",
"net.sf.jasperreports" % "jasperreports" % "6.3.1",
"com.github.jhonnymertz" % "java-wkhtmltopdf-wrapper" % "1.0.1-RELEASE",
"org.awaitility" % "awaitility-scala" % "2.0.0",
"org.fusesource.mqtt-client" % "mqtt-client" % "1.14")
jacoco.settings
parallelExecution in jacoco.Config := false
jacoco.reportFormats in jacoco.Config := Seq(
de.johoop.jacoco4sbt.ScalaHTMLReport(encoding = "utf-8", withBranchCoverage = true),
de.johoop.jacoco4sbt.XMLReport(encoding = "utf-8"))
fork in run := false
fork in Test := false
mappings in Universal <++= (packageBin in Compile) map { jar =>
val scriptsDir = new java.io.File("modules/abc-api/app/templates/")
scriptsDir.listFiles.toSeq.map { f =>
f -> ("app/templates/" + f.getName)
}
}
mappings in Universal <++= (packageBin in Compile) map { jar =>
val scriptsDir = new java.io.File("modules/abc-api/public/images/")
scriptsDir.listFiles.toSeq.map { f =>
f -> ("public/images/" + f.getName)
}
}
我不认为你可以这样做,项目是二进制绑定的,我的意思是所有模块 jar 都必须在 class 路径中(根据 build.sbt
)。你不能 运行 他们单独。
我希望您正在寻找的是微服务之类的东西。如果是这样,您需要了解微服务带来的成本。一旦决定使用微服务,您可以看看 Lagom Framework (https://www.lightbend.com/lagom)
我有戏! 2.5.3 project with one subproject(有自己的路线)。在主路由文件中,子项目的路由定义如下:
-> /api api.Routes
GET /assets/*file controllers.Assets.at(path="/public", file)
和api.routes
文件如下:
GET /v1/permissions/roles controllers.api.PermissionsController.roles
因此获得角色的 URL 将是 /api/v1/permissions/roles
。
当我 运行 根项目(依赖于两个子项目)时一切正常,但是当 运行 分别连接每个子项目时,找不到路由。我尝试在构建过程中将主路由文件复制到已构建子项目的 conf
文件夹中,但是没有用。
我找到的唯一解决方案是在 application.conf
中添加 play.http.router = "api.Routes"
,但是路由 "looses" 它的 /api
前缀(即:api 路由是/v1/permissions/roles
)
所以我的问题是:是否可以有一个带有路由的子项目,并且这些路由在 运行 根项目和每个 运行 时是相同的子项目分开?
如果可能的话,它在文档中的任何地方吗?
编辑:
build.sbt
用于根项目
name := """abc"""
version := "0.1.0"
scalaVersion := "2.11.7"
resolvers += Resolver.jcenterRepo
javaOptions in Test += "-Dconfig.file=conf/test.conf"
javaOptions in Test += "-Dtest.timeout=600000"
lazy val abcCore = (project in file("modules/abc-core")).enablePlugins(PlayJava, PlayEbean)
lazy val abcCentral = (project in file("modules/abc-central")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore)
.aggregate(abcCore)
lazy val abcSimulador = (project in file("modules/abc-simulador")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore)
.aggregate(abcCore)
lazy val abcDevice = (project in file("modules/abc-device")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore)
.aggregate(abcCore)
lazy val abcApi = (project in file("modules/abc-api")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore, abcSimulador)
.aggregate(abcCore, abcSimulador)
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
.dependsOn(abcCore, abcDevice, abcCentral, abcSimulador, abcApi)
.aggregate(abcCore, abcDevice, abcCentral, abcSimulador, abcApi)
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"uk.co.panaxiom" %% "play-jongo" % "2.0.0-jongo1.3",
"be.objectify" %% "deadbolt-java" % "2.5.0",
"mysql" % "mysql-connector-java" % "5.1.36",
"org.hibernate" % "hibernate-validator" % "5.2.4.Final",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.5",
"uk.co.modular-it" % "bean-utils" % "0.9.10",
"org.hamcrest" % "hamcrest-library" % "1.3",
"commons-beanutils" % "commons-beanutils" % "1.9.2",
"net.coobird" % "thumbnailator" % "0.4.8",
"io.moquette" % "moquette-broker" % "0.8.1" exclude("org.slf4j", "slf4j-log4j12"),
"org.mindrot" % "jbcrypt" % "0.3m",
"org.apache.commons" % "commons-math3" % "3.6.1",
"com.typesafe.play" %% "play-mailer" % "5.0.0",
"org.thymeleaf" % "thymeleaf" % "3.0.1.RELEASE",
"org.jetbrains.kotlin" % "kotlin-stdlib" % "1.0.3",
"org.eclipse.collections" % "eclipse-collections-api" % "7.1.0",
"org.eclipse.collections" % "eclipse-collections" % "7.1.0",
"org.eclipse.collections" % "eclipse-collections-forkjoin" % "7.1.0",
"net.jpountz.lz4" % "lz4" % "1.3.0",
"org.mapdb" % "elsa" % "3.0.0-M6",
"com.google.guava" % "guava" % "19.0",
"org.jfree" % "jfreesvg" % "3.1",
"net.sf.jasperreports" % "jasperreports" % "6.3.1",
"com.github.jhonnymertz" % "java-wkhtmltopdf-wrapper" % "1.0.1-RELEASE",
"org.awaitility" % "awaitility-scala" % "2.0.0",
"org.fusesource.mqtt-client" % "mqtt-client" % "1.14")
jacoco.settings
parallelExecution in jacoco.Config := false
jacoco.reportFormats in jacoco.Config := Seq(
de.johoop.jacoco4sbt.ScalaHTMLReport(encoding = "utf-8", withBranchCoverage = true),
de.johoop.jacoco4sbt.XMLReport(encoding = "utf-8"))
fork in run := false
fork in Test := false
mappings in Universal <++= (packageBin in Compile) map { jar =>
val scriptsDir = new java.io.File("modules/abc-api/app/templates/")
scriptsDir.listFiles.toSeq.map { f =>
f -> ("app/templates/" + f.getName)
}
}
mappings in Universal <++= (packageBin in Compile) map { jar =>
val scriptsDir = new java.io.File("modules/abc-api/public/images/")
scriptsDir.listFiles.toSeq.map { f =>
f -> ("public/images/" + f.getName)
}
}
我不认为你可以这样做,项目是二进制绑定的,我的意思是所有模块 jar 都必须在 class 路径中(根据 build.sbt
)。你不能 运行 他们单独。
我希望您正在寻找的是微服务之类的东西。如果是这样,您需要了解微服务带来的成本。一旦决定使用微服务,您可以看看 Lagom Framework (https://www.lightbend.com/lagom)