【发布时间】:2017-03-30 01:28:52
【问题描述】:
我已经使用 sbt 程序集打包了我的 Spring Boot 应用程序,并且在尝试运行我收到的 jar 时
Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is
org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
该项目在 Intellij 中运行良好。我的 build.sbt 在下面
lazy val news = (project in file("wherever")).
enablePlugins(DockerPlugin).
settings(commonSettings: _*).
settings(
name := "name",
mainClass in assembly := Some("mainEntry"),
test in assembly := {},
assemblyJarName := "jarName",
libraryDependencies ++= dependency1,
libraryDependencies ++= dependency2,
libraryDependencies += ScalaTest,
scalaSource in Compile := baseDirectory.value / "src/main/scala",
dockerfile in docker := {
val artifact: File = assembly.value
val artifactTargetPath = "/"
new Dockerfile {
from("openjdk:8-jre-alpine")
add(artifact, artifactTargetPath)
add(new File("./config/"),"/config")
cmd("java", "-jar", " -Denv=$env","jarName")
env("env","stage")
}
},
imageNames in docker := Seq(
ImageName("imageName")
)
)
我已经进行了一些挖掘,它看起来像Spring Boot requires the jar to contain nested jars(而不是像使用 sbt 程序集创建的 Uber jar)。所以,这给了我两个选择。使用 sbt 将我的 jar 打包为嵌套 jar,或者配置 spring 以使用普通的类加载器并从 Uber jar 加载。
我查看了嵌套的 jar sbt 插件,但似乎找不到任何维护的东西(甚至在 maven Central 中)。 This 和 this 都已过时且不在 Maven 中心。有没有人对此有任何建议?
我还研究了配置 spring boot 以使用 uber jars,压倒性的反应只是“使用 maven 插件”,这在此处不适用。
【问题讨论】:
标签: spring scala spring-boot sbt sbt-assembly