【问题标题】:Getting exception Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean由于缺少 EmbeddedServletContainerFactory bean,出现异常无法启动 EmbeddedWebApplicationContext
【发布时间】:2016-08-15 19:35:44
【问题描述】:

我收到以下异常。

Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

下面是我的 build.gradle

buildscript {
    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

ext {
   aemVersion='1.0.25'
   avroVersion = '1.8.0' 
   springWSVersion = '2.2.1.RELEASE'
   jibxMinorVersion = "5"
}

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

jar {
    baseName = 'abc'
    version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
   flatDir {
               dirs "${rootDir}/lib"
            }
    mavenLocal()
    mavenCentral()
    maven {
    name 'springFramework'
    url 'https://mvnrepository.com/artifact'
    }
}

dependencies {
    compile('org.apache.camel:camel-spring-boot-starter:2.17.2')
    compile('org.apache.camel:camel-kafka:2.17.2')
    compile group: 'org.apache.camel', name: 'camel-avro', version: '2.17.2'
    compile "org.springframework.ws:spring-ws-core:$springWSVersion"
    compile ('org.jdom:jdom:2.0.2')
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
    compile group: 'org.springframework.integration', name: 'spring-integration-kafka', version: '2.0.0.RELEASE'
    compile group: 'org.springframework.integration', name: 'spring-integration-core', version: '4.3.1.RELEASE'
    compile group: 'org.apache.kafka', name: 'kafka_2.10', version: '0.8.0'
    compile ('org.jibx:jibx-run:1.2.5'){
        exclude group: 'bcel', module: 'bcel'
    }
    testCompile ('org.jibx:jibx-extras:1.2.5'){
        exclude group: 'bcel', module: 'bcel'
    }
    compile("org.springframework.boot:spring-boot-starter")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

我的应用程序是一个非网络应用程序。我从命令行运行它并使用以下代码。

@SpringBootApplication
public class MyApplication implements CommandLineRunner{    
    @Autowired
    private Executor routeExecutor;

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
    @Override
    public void run(String... args) throws Exception {
        System.out.println("Running Application from run method..");
        this.routeExecutor.executeRoute();
    }
}

我不想要tomcat。我已经寻找过这个异常,它是一个常见的异常,但我不想添加“spring-boot-starter-web”依赖项,因为它是一个非 Web 应用程序。请帮帮我

【问题讨论】:

  • 可能是因为您使用的是网络服务。 Spring-ws,骆驼和卡夫卡。可能其中一些正在添加网络依赖项。

标签: spring exception spring-boot


【解决方案1】:

Spring Boot 错误地猜测您正在尝试基于类路径中的内容构建 Web 应用程序。您可以通过使用SpringApplicationBuilder 并在您的main 方法中将web 设置为false 来纠正它:

public static void main(String[] args) {
    new SpringApplicationBuilder(MyApplication.class).web(false).run(args);
}

【讨论】:

    猜你喜欢
    • 2015-03-19
    • 2016-05-06
    • 1970-01-01
    • 2016-03-05
    • 2014-07-28
    • 2017-03-30
    • 1970-01-01
    • 2015-07-31
    • 2014-03-14
    相关资源
    最近更新 更多