gradle - spring-boot-starter-jetty 1.4.x.RELEASE缺少EmbeddedServletContainerFactory

标签 gradle spring-boot jetty

使用以下gradle配置时:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-starter-app'
    version =  '0.1.0'
}

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
}

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
    compile.exclude module: "spring-boot-starter-logging"
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-actuator:1.4.1.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-jetty:1.4.1.RELEASE")
    compile('org.springframework.boot:spring-boot-starter-log4j2:1.4.1.RELEASE')
    testCompile("org.springframework.boot:spring-boot-starter-test:1.4.1.RELEASE")
    testCompile("junit:junit")
}
```
The app won't start up, the exception being:
```
2016-11-07 09:36:22.900 ERROR 44150 --- [           main] o.s.b.SpringApplication                  : 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.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at com.mystuff.Application.main(Application.java:10) [main/:?]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:189) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    ... 8 more

注意:我也在1.4.0中尝试过。
但是当我回退到1.3.x.RELEASE时,所有方法都起作用:
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.8.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'gs-starter-app'
    version =  '0.1.0'
}

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
}

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
    compile.exclude module: "spring-boot-starter-logging"
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.3.8.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-actuator:1.3.8.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-jetty:1.3.8.RELEASE")
    compile('org.springframework.boot:spring-boot-starter-log4j2:1.3.8.RELEASE')
    testCompile("org.springframework.boot:spring-boot-starter-test:1.3.8.RELEASE")
    testCompile("junit:junit")
}

我的应用程序类如下所示:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class);
    }

}

谷歌搜索显示,最常见的原因是:
  • 缺少spring-boot-starter-web依赖项-此处不是
  • 一个缺少的Maven插件-在这里不合适

  • 为什么会这样?

    最佳答案

    1.4.x使用需要Java 8的Jetty 9.3
    我在构建脚本中看到您正在使用Java7。Spring Boot 1.4.x使用Jetty 9.3,它需要Java 8(see Spring Boot's Jetty vs Java versions)
    Java 7-回退到Jetty 9.2
    如果不能升级到Java 8,则需要使用Jetty 9.2(see how-to-use-jetty-9.2-gradle)。这可以通过重新定义属性jetty.version来完成:

    ext['jetty.version'] = '9.2.17.v20160517'
    dependencies {
        compile ('org.springframework.boot:spring-boot-starter-web') {
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
        }
        compile ('org.springframework.boot:spring-boot-starter-jetty')
    }
    

    关于gradle - spring-boot-starter-jetty 1.4.x.RELEASE缺少EmbeddedServletContainerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40462147/

    相关文章:

    spring-boot - Spring Boot Rest 多语言

    java - Spring boot - 循环bean依赖问题

    spring - 在 docker-compose 中的 spring boot 应用程序中使用外部配置

    java - Jetty 通过多部分请求直接将文件上传到 FileInputStream

    performance - 我应该在反向代理设置中使用 Jetty 还是 NGINX 的 gzip 功能?

    gradle - CircleCI 是否能够在没有额外插件的情况下解释通过 Gradle 生成的 JUnit XML 结果?

    eclipse - 如何在Eclipse中使用sqlbrite和RxJava 1.x?

    ssl - Jetty 配置以禁用所有 SSL 检查

    spring-boot - 如何:使用外部配置文件构建Gradle Spring Boot应用

    Gradle多项目并没有产生Lombok的优点