zoukankan      html  css  js  c++  java
  • springboot问题:解决异常Unable to start embedded container;

    使用eclipse创建springboot练习时,当主函数与控制器同时写在同一个类时,启动项目正常运行,而当把主函数单独放在一个类中时,无论是与控制器同包还是控制器所在的包是其子包,都报:

    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:137) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at com.itmacy.app.HelloSpringBootApp.main(HelloSpringBootApp.java:19) [classes/: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:189) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
        ... 8 common frames omitted

    解决方案:在控制器类上加上@EnableAutoConfiguration注解

    部分截图如下:

    1.当主函数与控制器写在同一个类上时:

    2.当主函数与控制器不在同一个类时:

  • 相关阅读:
    FW: MBA的学费一般在多少?学MBA有啥用?
    【悟】资本思维:这才是真正"赚大钱的逻辑"
    关于印发《北京市引进人才管理办法(试行)》的通知
    基于wordpress电商解决方案 + POS在线轻量级系统
    SAP Fasion FMS solution 时尚商品行业解决方案
    SAP IS-Retail Promotion and POS Bonus Buy integration
    SAP CARR for retails solution SAP零售集成方案
    Forest-一款比httpClient,okhttp更优雅人性化的http请求组件
    IDEA 日志插件 MyBatis Log Plugin 在线格式化日志工具
    Jenkins ERROR: Server rejected the 1 private key(s)
  • 原文地址:https://www.cnblogs.com/itmacy/p/6971161.html
Copyright © 2011-2022 走看看