복붙노트

[SPRING] 스프링 부트 - 누락 된 EmbeddedServletContainerFactory 빈으로 인해 EmbeddedWebApplicationContext를 시작할 수 없습니다.

SPRING

스프링 부트 - 누락 된 EmbeddedServletContainerFactory 빈으로 인해 EmbeddedWebApplicationContext를 시작할 수 없습니다.

봄 부츠

intelliJ에서 봄 부팅 응용 프로그램을 실행하려고했지만 오류가 발생했습니다.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.1.RELEASE)

2016-01-26 23:09:30.883  INFO 3960 --- [           main] com.example.he.ExampleApplication         : Starting ExampleApplication on user with PID 3960 (F:\WORK\Work_Project\Example_Application-master\Example_Application-master\build\classes\main started by user in F:\WORK\Work_Project\Example_Application-master\Example_Application-master)
2016-01-26 23:09:30.892  INFO 3960 --- [           main] com.example.he.ExampleApplication         : No active profile set, falling back to default profiles: default
2016-01-26 23:09:31.042  INFO 3960 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@73d4cc9e: startup date [Tue Jan 26 23:09:31 IST 2016]; root of context hierarchy
2016-01-26 23:09:31.242  WARN 3960 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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.
2016-01-26 23:09:31.453 ERROR 3960 --- [           main] o.s.boot.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:133) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at com.example.he.ExampleApplication.main(ExampleApplication.java:15) [main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:na]
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:185) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    ... 13 common frames omitted

2016-01-26 23:09:31.456  INFO 3960 --- 

Process finished with exit code 1

이드 사용 Gradle.This 내 build.gradle 파일입니다 :

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

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

war {
    baseName = 'Example-Application'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.0.30')
        compile('javax.servlet:servlet-api:2.5')
    compile('javax.servlet:jstl:1.2')
    runtime('mysql:mysql-connector-java')
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}


eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

다음은 구성 클래스입니다.

package com.example.he.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/city").setViewName("city");
    registry.addViewController("/").setViewName("city");
    registry.addViewController("/userAdd").setViewName("user");
    registry.addViewController("/created").setViewName("created");
    registry.addViewController("/createblog").setViewName("blog");
    registry.addViewController("/login").setViewName("login");
    registry.addViewController("/home").setViewName("home");

  }

}

그리고 이것은 내 Application 클래스입니다.

package com.example.he;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
public class ExampleApplication extends SpringBootServletInitializer{

    public static void main(String[] args) throws Exception {
        SpringApplication.run(ExampleApplication.class, args);
    }


  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(ExampleApplication.class);
  }


}

그리고 나는 또한 이러한 주석을 시도했다.

@ComponentScan
@EnableAutoConfiguration
@Configuration

나는 봄에 익숙하지 않고 이러한 주석이 무엇을하는지 이해하지 못합니다.이 중 일부를 시도했지만 문제를 해결할 수 없습니다.

스프링 부트 : 누락 된 EmbeddedServletContainerFactory 빈으로 인해 EmbeddedWebApplicationContext를 시작할 수 없습니다.

스프링 부트 테스트 : EmbeddedServletContainerFactory 빈이 없어서 EmbeddedWebApplicationContext를 시작할 수 없습니다.

내가 콘솔 (gradle 빌드)를 사용하여 응용 프로그램을 구축, 빌드 성공했지만 전쟁을 실행하면 오류가 발생합니다 : 임베디드 Tomcat을 시작할 수 없습니다. 누군가 나를 도울 수 있을까요?

해결법

  1. ==============================

    1.나는 당신의 응용 프로그램을 가동시킬 수있었습니다. 빌드를 실행하기 위해 만든 유일한 변경 사항은 build.gradle 파일에서 몇 가지 종속성을 주석 처리하는 것입니다.

    나는 당신의 응용 프로그램을 가동시킬 수있었습니다. 빌드를 실행하기 위해 만든 유일한 변경 사항은 build.gradle 파일에서 몇 가지 종속성을 주석 처리하는 것입니다.

    아래 의존성 블록에서 3 줄을 주석 처리했습니다. spring-boot-start-jpa 줄은 필자가 구성된 dataSource가 없기 때문에 주석 처리했다.

    그러나 servlet-api 및 jstl 종속성 만 주석 처리하면 응용 프로그램이 문제없이 시작되어야합니다.

    dependencies {
        //compile('org.springframework.boot:spring-boot-starter-data-jpa')
        compile('org.springframework.boot:spring-boot-starter-security')
        compile('org.springframework.boot:spring-boot-starter-web')
        compile('org.apache.tomcat.embed:tomcat-embed-jasper:8.0.30')
        //compile('javax.servlet:servlet-api:2.5')
        //compile('javax.servlet:jstl:1.2')
        runtime('mysql:mysql-connector-java')
        providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }
    
  2. ==============================

    2.또한이 오류가 있으며 Intellij에서만 발생합니다. 마침내 나는 이것에 대해 주석을 달아서 작동시켰다.

    또한이 오류가 있으며 Intellij에서만 발생합니다. 마침내 나는 이것에 대해 주석을 달아서 작동시켰다.

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-tomcat</artifactId>
         <scope>provided</scope>
    </dependency>
    

    이 사실을 알아 내는데 많은 시간이 걸렸습니다. 희망이 비슷한 오류가 발생하는 사람들을 도와줍니다.

  3. ==============================

    3.내 경우에는 pom.xml에 추가하지 않았다.

    내 경우에는 pom.xml에 추가하지 않았다.

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.2.5.RELEASE</version>
        </parent>
    
  4. ==============================

    4.메인 부팅 응용 프로그램 클래스에 주석을 추가하면 저에게 효과적이었습니다. @EnableAutoConfiguration 공용 클래스 ExampleApplication {.....

    메인 부팅 응용 프로그램 클래스에 주석을 추가하면 저에게 효과적이었습니다. @EnableAutoConfiguration 공용 클래스 ExampleApplication {.....

  5. ==============================

    5.C : \ Users \ Lenovo \ .m2 \ repository를 청소 한 다음 모든 종속성을 다시 가져 오면 저에게 효과적입니다. 또한 pom.xml의 모든 재정의 종속성을 삭제했습니다.

    C : \ Users \ Lenovo \ .m2 \ repository를 청소 한 다음 모든 종속성을 다시 가져 오면 저에게 효과적입니다. 또한 pom.xml의 모든 재정의 종속성을 삭제했습니다.

  6. from https://stackoverflow.com/questions/35021328/spring-boot-unable-to-start-embeddedwebapplicationcontext-due-to-missing-embe by cc-by-sa and MIT license