IT박스

스프링 부트 : EmbeddedServletContainerFactory 빈이 없어서 EmbeddedWebApplicationContext를 시작할 수 없음

itboxs 2020. 5. 30. 22:26
반응형

스프링 부트 : EmbeddedServletContainerFactory 빈이 없어서 EmbeddedWebApplicationContext를 시작할 수 없음


나는 Spring을 완전히 처음 접 했고이 사이트에서 공식 가이드를 시작했습니다 : https://spring.io/guides

이 안내서를 수행하고 싶습니다 : https://spring.io/guides/gs/scheduling-tasks/

다음과 같은 예외가 발생합니다.

2014-02-14 16:25:21.614  INFO 9032 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerByCGLIB$$5b48d763] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2014-02-14 16:25:21.638  INFO 9032 --- [           main] .c.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/C:/work/Spring/SpringTutorial/target/classes/, file:/C:/work/apache-maven-3.0.3/repo/javax/servlet/javax.servlet-api/3.0.1/javax.servlet-api-3.0.1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter/1.0.0.RC1/spring-boot-starter-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot/1.0.0.RC1/spring-boot-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-core/4.0.0.RELEASE/spring-core-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-context/4.0.0.RELEASE/spring-context-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-autoconfigure/1.0.0.RC1/spring-boot-autoconfigure-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-logging/1.0.0.RC1/spring-boot-starter-logging-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/jcl-over-slf4j/1.7.5/jcl-over-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/jul-to-slf4j/1.7.5/jul-to-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/org/slf4j/log4j-over-slf4j/1.7.5/log4j-over-slf4j-1.7.5.jar, file:/C:/work/apache-maven-3.0.3/repo/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar, file:/C:/work/apache-maven-3.0.3/repo/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-web/1.0.0.RC1/spring-boot-starter-web-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/boot/spring-boot-starter-tomcat/1.0.0.RC1/spring-boot-starter-tomcat-1.0.0.RC1.jar, file:/C:/work/apache-maven-3.0.3/repo/org/apache/tomcat/embed/tomcat-embed-core/7.0.47/tomcat-embed-core-7.0.47.jar, file:/C:/work/apache-maven-3.0.3/repo/org/apache/tomcat/embed/tomcat-embed-logging-juli/7.0.47/tomcat-embed-logging-juli-7.0.47.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-web/4.0.0.RELEASE/spring-web-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-aop/4.0.0.RELEASE/spring-aop-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-beans/4.0.0.RELEASE/spring-beans-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-webmvc/4.0.0.RELEASE/spring-webmvc-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/org/springframework/spring-expression/4.0.0.RELEASE/spring-expression-4.0.0.RELEASE.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-databind/2.3.1/jackson-databind-2.3.1.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar, file:/C:/work/apache-maven-3.0.3/repo/com/fasterxml/jackson/core/jackson-core/2.3.1/jackson-core-2.3.1.jar, file:/C:/work/apache-maven-3.0.3/repo/commons-lang/commons-lang/2.2/commons-lang-2.2.jar]
Exception in thread "main" 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:140)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:658)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:355)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:920)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
    at hu.kumite.Application.main(Application.java:17)
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:190)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:163)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
    ... 7 more

응용 프로그램 시작 클래스는 다음과 같습니다.

@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(ScheduledTasks.class, args);
    }
}

보시다시피, 주요 메소드에는 주석 처리 된 행이 있습니다. 이미 튜토리얼을 완료했습니다. https://spring.io/guides/gs/ consumer-rest / 작동하고 있습니다. 그러나 다음과 같은 ScheduledTasks 앱을 실행할 수 없습니다.

@EnableScheduling
public class ScheduledTasks {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        System.out.println("The time is now " + dateFormat.format(new Date()));
    }
}

Eclipse를 사용하고 Application.java의 main을 Application으로 실행합니다. 누군가 제발 도와주세요?


스케줄링 가이드는 웹 앱이 아니므로 REST 가이드의 pom.xml에 곰팡이가 있습니까? 지침을 자세히 따르면 제대로 작동합니다. 위에 게시 한 코드의 또 다른 잠재적 인 문제는 @EnableAutoConfiguration클래스가 컨텍스트에서 주된 방법으로 만 사용되지 않는다는 것입니다 (스케줄링 가이드에는 문제가되지 않지만 다른 많은 사람들에게는 문제 일 수 있음).


@SpringBootApplication쇼를 스캔 하면 다음과 같은 주석이 포함됩니다.

@Configuration
@ComponentScan
@EnableAutoConfiguration

그래서 당신도 이것을 할 수 있습니다 :

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

pom.xml에서 이것을 사용하십시오 :

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>

또는 이것 :

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

이 시도

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
       SpringApplication.run(ScheduledTasks.class, args);
    }
}

하나의 Spring Boot 프로젝트에 여러 개의 응용 프로그램 클래스가 있었는데 웹에 포함되어 있고 그중 하나에 대한 웹 환경을 구성하지 않기 위해 수동으로 구성했습니다.

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

스프링 부트 2 이상 업데이트 :

@SpringBootApplication
public class Application
{
    public static void main(String[] args)
    {
        new SpringApplicationBuilder(Application.class)
            .web(WebApplicationType.NONE)
            .run(args);
    }
}

이 오류는 실행하려는 응용 프로그램이 Apache Tomcat 인스턴스를 인스턴스화 할 수 없음을 나타냅니다. 바람둥이로 응용 프로그램을 실행하고 있는지 확인하십시오.

모든 종속성을 확인한 후에도 동일한 문제가 발생하면 구성 클래스에 다음을 추가하십시오.

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = 
                  new TomcatEmbeddedServletContainerFactory();
    return factory;
 }

Tomcat의 외부 인스턴스 (특히 intellij)를 사용하는 경우 IDE에서 임베디드 Tomcat을 시작하려고 할 때 문제가 발생할 수 있습니다. 이 경우 pom.xml에서 다음을 제거하고 '구성 편집'마법사를 사용하여 외부 바람둥이를 구성하십시오.

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

더하다

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

intellij를 사용하는 동안이 예외가 발생하고 run버튼으로 응용 프로그램을 시작하려고하는 경우 대신 명령 행에서 응용 프로그램을 시작하십시오. 예를 들어 이것이 springboot응용 프로그램 실행 이라고 가정하면 올바른 디렉토리 (pom 파일이있는 디렉토리)에 있는지 확인 mvn spring-boot:run하십시오.

또한 스프링 응용 프로그램이 다른 응용 프로그램에 의존 할 때이 오류가 발생하는 것을 보았습니다. 이 경우 다른 응용 프로그램을 먼저 시작한 다음 실행해야했습니다.


주석 추가 @SpringBootApplication초보자 클래스 가이 문제를 해결하기 전에 (실제로이 오류 메시지는 " @SpringBootApplication어디에 든 표시된 클래스 가 없으며 적어도 하나가 필요합니다 "를 의미 할 수 있음 )

@SpringBootApplication
public class AppStarter {

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

I've had similar problems when the main method is on a different class than that passed to SpringApplcation.run()

So the solution would be to use the line you've commented out:

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

If you package it as a single jar and it's non web app try to load app context as below.

@SpringBootApplication

ApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class);

Or use below plugin to package as a single jar

             <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

you can specify the external configs by using below command to run

java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

/http://docs.spring.io/spring-boot/docs/current/reference/htmlboot-features-external-config.html#boot-features-external-config-application-property-files

Note that if you are passing the properties as arguments then don't include @PropertySource("classpath:test.properties") it will override the parameters


If you run it successfully using command line gradle bootRun, while packaging it with command line gradle jar to jar file in order to run it with command line java -jar build/libs/demo.jar, unfortunately, it failed with Exception: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean, in this case, you need to use task bootRepackage of gradle plugin spring-boot to generate special runnable jar.

  • setup 1

    $ gradle clean bootRepackage

  • setup 2

    $ java -jar build/libs/demo.jar


A SpringApplication will attempt to create the right type of ApplicationContext on your behalf. By default, an AnnotationConfigApplicationContext or AnnotationConfigEmbeddedWebApplicationContext will be used, depending on whether you are developing a web application or not.

The algorithm used to determine a ‘web environment’ is fairly simplistic (based on the presence of a few classes). You can use setWebEnvironment(boolean webEnvironment) if you need to override the default.

It is also possible to take complete control of the ApplicationContext type that will be used by calling setApplicationContextClass(…​).

[Tip] It is often desirable to call setWebEnvironment(false) when using SpringApplication within a JUnit test.


Adding the spring boot starter dependency fixed my error.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

This is required if you want to start the tomcat as an embeded server.


check your pom.xml is exists

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

I've had a problem like this;For lack this dependency


In my case we added the @Profile annotation newly in order to ignore the TestApplication class in production mode and the Application class in test mode.

Unfortunately, we forgot to add the following line into the application.properties files:

spring.profiles.active=test
or
spring.profiles.active=production

Without these config no profile was loaded which caused the not-so-much saying Spring Error.


This should be caused by dependency issue, in general, you need to check the dependency.


The problem it's in this class:

@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
    //SpringApplication.run(Application.class, args);
    SpringApplication.run(ScheduledTasks.class, args);
    }
}

The correct way to launch your application is:

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

Clear repository is one possible solution.

Windows -> delete all subfolders in the maven repository:

C:\Users\YourUserName.m2\repository


Problem is exclusion of starter tomcat, I tried exclude it and use vert.x, so when I integrate wit Spring Admin, started problems

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

I had this Exception in the following situation.

in my POM was properties:

<properties>
    <java.version>1.8</java.version>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.scmaer.java.microservice.Application</start-class>
    <cxf.version>3.1.5</cxf.version>
    <olingo.version>2.0.10</olingo.version>
    <spring.boot.version>1.4.7.RELEASE</spring.boot.version>
    <spring.boot.plugin.version>1.5.8.RELEASE</spring.boot.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <skipTests>false</skipTests>
</properties>

and the name and path of my application class ("start-class") was wrong.


I have stuck with same problem. As I didn't define Main.class and the following annotations in Spring-Boot using Maven:

@SpringBootApplication
public class Main {
    public static void main(String args[]){
        SpringApplication.run(Main.class, args);
    }
}

I had a similar issue and the problem was a broken maven repo jar file. In my case, the tomcat-embed-core jar file was broken. So I removed it from the maven repo and refreshed it to download again.


In my case it happen after excluding the resource folder from the pom using the following code.

<resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>*/*.properties</exclude>
            </excludes>
        </resource>
</resources>

Commenting this code started my code.


An other cause of this problem is corruption of maven repository jars so you can use the following command to solve the problem :

mvn dependency:purge-local-repository

Probably you missing @SpringBootApplication in your spring boot starter class.

@SpringBootApplication
public class LoginSecurityAppApplication {

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

}

참고URL : https://stackoverflow.com/questions/21783391/spring-boot-unable-to-start-embeddedwebapplicationcontext-due-to-missing-embedd

반응형