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

时间:2016-11-07 09:49:40

标签: 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);
    }

}

谷歌搜索显示最常见的原因是:

  1. 缺少spring-boot-starter-web依赖 - 而不是这里的情况
  2. 一个丢失的maven插件 - 这里不合适
  3. 为什么会这样?

1 个答案:

答案 0 :(得分:1)

1.4.x使用Jetty 9.3,它需要java 8

我在构建脚本中看到你正在使用Java 7. 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')
}