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
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值