从Spring Boot到Jetty部署独立war文件

时间:2014-08-15 12:37:31

标签: jetty spring-boot

我试图将使用Spring Boot构建的war文件部署到独立的Jetty webapps文件夹并启动Jetty。在Spring上下文初始化期间,我看到了异常:

Caused by: 
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.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)

下面是我的gradle依赖列表:

dependencies {
    compile(
        "org.springframework.boot:spring-boot-starter-actuator:1.1.4.RELEASE",
        "org.springframework.security:spring-security-web:3.2.3.RELEASE",
        "org.springframework.security:spring-security-config:3.2.3.RELEASE",
        'javax.validation:validation-api:1.0.0.GA',
        'org.hibernate:hibernate-validator:4.0.0.GA',
        "org.codehaus.groovy:groovy-all:2.1.1",
        'com.google.code.gson:gson:2.2.1',
        "javax.servlet:javax.servlet-api:3.1.0",
        "com.sun.jersey:jersey-server:1.16",
        "com.sun.jersey:jersey-client:1.16",
        "com.sun.jersey:jersey-core:1.16",
        "com.fasterxml.jackson.jaxrs:jackson-jaxrs-providers:2.3.2",
        "com.sun.jersey:jersey-servlet:1.16",
        "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.3.2",
        "com.sun.jersey.contribs:jersey-spring:1.16",
        "org.springframework:spring-beans:4.0.6.RELEASE",
        'com.wordnik:swagger-jersey-jaxrs_2.10:1.3.5',
        'com.fasterxml.jackson.core:jackson-core:2.3.0',
        "org.springframework:spring-web:4.0.6.RELEASE",
        "org.springframework:spring-core:4.0.6.RELEASE",
        "org.springframework:spring-tx:4.0.6.RELEASE",
        "org.springframework:spring-expression:4.0.6.RELEASE",
        "org.springframework:spring-webmvc:4.0.6.RELEASE",
        "org.springframework:spring-context:4.0.6.RELEASE",
        "org.jasypt:jasypt-spring3:1.9.1",
        "com.sun.jersey.contribs:jersey-multipart:1.16",
        "org.aspectj:aspectjweaver:1.7.4",
        "org.springframework:spring-aspects:4.0.6.RELEASE",
        "org.springframework:spring-aop:4.0.6.RELEASE",
        'javax.validation:validation-api:1.0.0.GA',
        'org.hibernate:hibernate-validator:4.0.0.GA'
    )
    compile ("org.springframework.boot:spring-boot-starter-web:1.1.4.RELEASE") {
        exclude module:'spring-boot-starter-tomcat'
    }

我正在使用Spring引导文档中建议的ApplicationInitializer类。我错过了什么?如何通过此例外?我有Jetty 9.x服务器。

class ApplicationInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        Properties props = getPropertiesFromArgs()
        return new SpringApplicationBuilder([Application, "classpath:/META-INF/com/foo/testapp/bootstrap.xml"] as Object[])
            .properties(props)
    }

1 个答案:

答案 0 :(得分:1)

发现了这个问题。 initializer类正在创建一个新的应用程序构建器,而不是使用输入参数。将其改为以下工作正常。

class ApplicationInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        Properties props = getPropertiesFromArgs()     
        return application.sources([Application, "classpath:/META-INF/com/foo/testapp/bootstrap.xml"] as Object[])
            .properties(props)

    }