Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

Spring Boot启动出现错误,错误内容大概的意思是:未能加载嵌入的供web应用加载的空间,是因为缺少EmbeddedServletContainerFactory bean,在stackflow上面看到了这个错误的解决办法,原文如下:

The scheduling guide isn't a web app so you probably have some mouldy stuff in your pom.xml from the REST guide? If you follow the instructions closely it should work. Another potential issue with the code you posted above is that your  @EnableAutoConfiguration class is not used in the context, only as a main method (which may not be a problem for the scheduling guide but it probably is for a bunch of others).

也就是说解决的办法是在SpringBoot启动类上加一个@EnableAutoConfiguration注解,但是毕竟是Spring Boot啊,只需要一个@SpringBootApplication注解即可搞定,因为@SpringBoootApplication注解已经带了@EnableAutoConfiguration注解,并且还封装了其他的注解,看看@SpringBootApplication的定义(注释省略):

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Configuration
@EnableAutoConfiguration
@ComponentScan
public @interface SpringBootApplication {

	Class[] exclude() default {};

	String[] excludeName() default {};

	@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
	String[] scanBasePackages() default {};

	@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
	Class[] scanBasePackageClasses() default {};

}

我的问题是添加一个@SpringBootApplication注解来解决的:

package com.lanchangtou.app;

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, args);
    }

}

当然是根据情况会出现这个问题,如果内嵌的tomcat版本不匹配也会有这个问题,也就是说在项目中又引入了一个Tomcat会出问题。


statckoverflow原文链接:http://stackoverflow.com/questions/21783391/spring-boot-unable-to-start-embeddedwebapplicationcontext-due-to-missing-embedd

你可能感兴趣的:(Spring,Boot,Spring,Boot)