2016-11-16 17 views
1

の欠落にEmbeddedWebApplicationContextを開始することができません私は、SBTのアセンブリを使用して、私の春のブートアプリケーションをパッケージ化して、私は春ブーツ:原因EmbeddedServletContainerFactory

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でだけで正常に動作受け取るjarファイルを実行しようとするとしています。私はいくつかの周りに掘っやったし、それが(代わりに、SBTのアセンブリを使用して作成されたようなユーバージャーの)Spring Boot requires the jar to contain nested jarsのように見えます

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") 
) 
) 

の下に私のbuild.sbtです。だから、2つの選択肢があります。私のjarファイルをsbtで入れ子にしてパッケージ化するか、通常のクラスローダーを使用してUber jarファイルからロードするようにspringを構成します。

私は入れ子になったjarのsbtプラグインを調べましたが、私は維持されているものを見つけることができませんでした(または中央のmavenでも)。 Thisthisは古いものであり、中央のものではありません。誰もこれを行うための任意の提案がありますか?

私はまた、uber jarを使用するようにスプリングブートを設定しました。圧倒的なレスポンスは、ここでは適用できない「mavenプラグインを使用する」ことです。

答えて

0

アプリケーションに埋め込みサーブレットコンテナファクトリを提供する必要があります。それは次のようになります。

import org.springframework.boot.SpringApplication 
import org.springframework.boot.autoconfigure.SpringBootApplication 
import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration 
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory 
import org.springframework.boot.context.web.SpringBootServletInitializer 
import org.springframework.context.annotation.{Bean, ComponentScan, Configuration, PropertySource} 

/** 
* Spring boot application configuration and servlet initializer. 
*/ 
@Configuration 
@ComponentScan(value = Array("com.foobusiness.foopackage")) 
@PropertySource(Array("classpath:application.properties")) 
@SpringBootApplication(exclude = Array(classOf[ErrorMvcAutoConfiguration])) 
class Application extends SpringBootServletInitializer { 
    @Bean 
    def servletContainer: JettyEmbeddedServletContainerFactory = new JettyEmbeddedServletContainerFactory() 
} 

object Application { 
    def main(args: Array[String]): Unit = { 
    SpringApplication run classOf[Application] 
    } 
} 

を上記のはあなたにも、ライブラリのコンパイル時の依存関係としてjetty-runnerを含める必要があるだろうことを意味する、明らかに、桟橋を使用しています。あなたのsbtビルドファイルも、コンパイル時に上記のクラスを使用する必要が実行されているかの包装:

mainClass in(Compile, run, packageBin) := Some("com.foobusiness.foopackage.Application"), 

アプリケーションがsbt run

と、コマンドラインから実行することができます