java 的 Play Framework 微服务模板项目

Microservices template project for Play Framework with java

我想使用 java 在 Play 2.5 中为微服务创建一个多项目 helloWorld,但我找不到任何合适的模板或教程来启动。 我的问题是我想创建一个可以同时 运行 并且都可以通过 REST 接口访问的项目。

有什么想法吗?

嘿嘿,都是sbt多项目配置示例:

name := "microservices"

scalaVersion in ThisBuild := "2.11.8"

autoScalaLibrary := false


def module(id: String, names: String) = Project(id, file(names))
  .settings(javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8", "-Xlint:unchecked", "-Xlint:deprecation"))
  .settings(jacksonParameterNamesJavacSettings: _*)

lazy val jacksonParameterNamesJavacSettings = Seq(
  javacOptions in compile += "-parameters"
)

lazy val common = module("common", "modules/common")
lazy val aws = module("aws", "modules/aws")
  .aggregate(common)
  .dependsOn(common)

lazy val keywords = module("keywords", "keywords")
  .enablePlugins(PlayJava, JavaAppPackaging, DockerPlugin)
  .dependsOn(common, aws)
  .aggregate(common, aws)

lazy val users = module("users", "users")
  .enablePlugins(PlayJava, JavaAppPackaging, DockerPlugin)
  .dependsOn(common, aws)
  .aggregate(common, aws)

文件夹结构示例:

  • 根:
    • 用户
      • 项目
    • 关键字
      • 项目
    • 模块:
      • 普通
      • aws

users/build.sbt

name := """users"""
scalaVersion in ThisBuild := "2.11.8"
PlayKeys.devSettings := Seq("play.server.http.port" -> "9001")
// application version release
version := "2.8"

libraryDependencies ++= Seq(
  cache,
  javaWs,
  "junit" % "junit" % "4.12",
  "org.mockito" % "mockito-all" % "1.10.19",
  "mysql" % "mysql-connector-java" % "6.0.4"
)

routesGenerator := InjectedRoutesGenerator

dockerExposedPorts in Docker := Seq(9001)

keywords/build.sbt

name := """keywords"""

PlayKeys.devSettings := Seq("play.server.http.port" -> "9002")
scalaVersion in ThisBuild := "2.11.8"
// application version release
version := "1.0"


libraryDependencies ++= Seq(
  cache,
  javaWs,
  "junit" % "junit" % "4.12",
  "org.mockito" % "mockito-all" % "1.10.19",
  "mysql" % "mysql-connector-java" % "6.0.4"
)

routesGenerator := InjectedRoutesGenerator

dockerExposedPorts in Docker := Seq(9000)

然后您需要 运行 sbt 并导航到所需的项目和 运行 它以便您 运行 它们作为两个独立的进程:

  • 1 个进程:
    • sbt;项目用户; 运行;
    • 这将在 9001运行
  • 2个过程:
    • sbt;项目关键词; 运行;
    • 这将在 9002运行

我明天 github 会为您提供示例模板。