启动Springboot项目报以下异常:

  

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at hello.Application.main(Application.java:13) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]...8 common frames omitte

  很明显是提示Application无法获取ServletWebServerFactory实例,首先要注意, 由于Springboot在以往使用Spring都要配置下提供了集成方案,所以最简单的方法就是采用默认的配置,解决方法非常简单,只需在你的启动类中加入@EnableAutoConfiguration,当然你也可以手动配置,如下为自动配置。

packagehello;importorg.springframework.boot.CommandLineRunner;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;importorg.springframework.context.ApplicationContext;importorg.springframework.context.annotation.Bean;importjava.util.Arrays;
@EnableAutoConfigurationpublic classApplication {public static voidmain(String[] args) {SpringApplication.run(Application.class, args);}@BeanpublicCommandLineRunner commandLineRunner(ApplicationContext ctx) {return args ->{System.out.println("Let's inspect the beans provided by Spring Boot:");String[] beanNames=ctx.getBeanDefinitionNames();Arrays.sort(beanNames);for(String beanName : beanNames) {System.out.println(beanName);}};}
}

  手动配置请参考官网,地址:https://docs.spring.io/spring-boot/docs/2.0.1.BUILD-SNAPSHOT/reference/html/howto-embedded-web-servers.html#howto-configure-tomcat

  下面配一个全部手动配置的代码,其中@value标签的内容需要自己写properties文件:

packagecom.gws.configuration;importorg.apache.catalina.connector.Connector;importorg.springframework.beans.factory.annotation.Value;importorg.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;importorg.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;importorg.springframework.boot.web.servlet.MultipartConfigFactory;importorg.springframework.boot.web.servlet.server.ServletWebServerFactory;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importjavax.servlet.MultipartConfigElement;/*** 使用tomcat配置**@version*@author**/@Configurationpublic classTomcatConfig {@Value("${spring.server.port}")privateString port;@Value("${spring.server.acceptorThreadCount}")privateString acceptorThreadCount;@Value("${spring.server.minSpareThreads}")privateString minSpareThreads;@Value("${spring.server.maxSpareThreads}")privateString maxSpareThreads;@Value("${spring.server.maxThreads}")privateString maxThreads;@Value("${spring.server.maxConnections}")privateString maxConnections;@Value("${spring.server.protocol}")privateString protocol;@Value("${spring.server.redirectPort}")privateString redirectPort;@Value("${spring.server.compression}")privateString compression;@Value("${spring.server.connectionTimeout}")privateString connectionTimeout;@Value("${spring.server.MaxFileSize}")privateString MaxFileSize;@Value("${spring.server.MaxRequestSize}")privateString MaxRequestSize;@BeanpublicServletWebServerFactory servletContainer() {TomcatServletWebServerFactory tomcat= newTomcatServletWebServerFactory();tomcat.addConnectorCustomizers(newGwsTomcatConnectionCustomizer());returntomcat;}@BeanpublicMultipartConfigElement multipartConfigElement() {MultipartConfigFactory factory= newMultipartConfigFactory();//单个数据大小factory.setMaxFileSize(MaxFileSize); //KB,MB/// 总上传数据大小
factory.setMaxRequestSize(MaxRequestSize);returnfactory.createMultipartConfig();}/**** 默认http连接**@version*@authorliuyi  2016年7月20日 下午7:59:41**/public class GwsTomcatConnectionCustomizer implementsTomcatConnectorCustomizer {publicGwsTomcatConnectionCustomizer() {}@Overridepublic voidcustomize(Connector connector) {connector.setPort(Integer.valueOf(port));connector.setAttribute("connectionTimeout", connectionTimeout);connector.setAttribute("acceptorThreadCount", acceptorThreadCount);connector.setAttribute("minSpareThreads", minSpareThreads);connector.setAttribute("maxSpareThreads", maxSpareThreads);connector.setAttribute("maxThreads", maxThreads);connector.setAttribute("maxConnections", maxConnections);connector.setAttribute("protocol", protocol);connector.setAttribute("redirectPort", "redirectPort");connector.setAttribute("compression", "compression");}}
}

转载于:https://www.cnblogs.com/iCanhua/p/8855430.html

记一次Springboot启动异常相关推荐

  1. 记一次SpringBoot启动异常,jar问题的排查分析

    点击上方"芋道源码",选择"设为星标" 管她前浪,还是后浪? 能浪的浪,才是好浪! 每天 10:33 更新文章,每天掉亿点点头发... 源码精品专栏 原创 | ...

  2. springboot启动异常java.lang.NoSuchFieldError: DEFAULT_INCOMPATIBLE_IMPROVEMENTS

    springboot启动异常java.lang.NoSuchFieldError: DEFAULT_INCOMPATIBLE_IMPROVEMENTS 参考文章: (1)springboot启动异常j ...

  3. springboot启动异常[ The last packet sent successfully to the server was 0 milliseconds ago. ]

    异常  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not recei ...

  4. springboot 两个src_记一次Springboot 启动错误(二)-Go语言中文社区

    解决异常需要用到的文件 2019-1-14 补充: 帮同事安装项目时又遇到这个问题 但是是以另外一种方式呈现: 错误信息: {com.ruoyi.project.platform.message.ma ...

  5. springBoot启动异常【Consider defining a bean of type】解决

    启动时报异常Consider defining a bean of type 'xxx' in your configuration. 异常原因:未加@Component,导致未检测到 解决方法:往类 ...

  6. springboot启动总是启动不起来UnsatisfiedDependencyException异常

    springboot启动总是启动不起来UnsatisfiedDependencyException异常 参考文章: (1)springboot启动总是启动不起来UnsatisfiedDependenc ...

  7. Springboot 启动时Bean初始化,启动异常-Assert.isTrue(condition,message) 报错

    Springboot 启动时Bean初始化启动异常Assert.isTrue(condition,message) 报错,如果 condition为false 则会出现 java.lang.Illeg ...

  8. springboot启动报jar包加载异常问题解决

    问题描述: springboot启动报jar包扫描错误,但不影响项目正常使用: Failed to scan [file:/Users/ds/.m2/repository/com/sun/xml/bi ...

  9. 启动rrt什么意思_面试官:你来说一下springboot启动时的一个自动装配过程吧!...

    前言 继续总结吧,没有面试就继续夯实自己的基础,前阵子的在面试过程中遇到的各种问题陆陆续续都会总结出来分享给大家,这次要说的也是面试中被问到的一个高频的问题,我当时其实没答好,因为很早之前是看过spr ...

最新文章

  1. dataframe 按条件删行_根据列值删除Pandas中的DataFrame行
  2. Develop Smartphone Device use VS.NET 2003
  3. 从MSSQL添加对Oracle的链接服务器的存储过程
  4. IT员工应该向谁汇报工作,CFO or CEO?
  5. Linux设置root默认密码
  6. DOM-3 【utils/待讲评】节点属性、方法、封装方法、DOM结构
  7. 解决替换weblogic的commons-fileupload.jar后引发的问题
  8. C语言试题十三之求出1到100之内能被7或者11整除,但不能同时被7和11整除的所有整书,并将他们放在a所指的数组中,通过n返回这些数的个数。
  9. VS2010中使用sprintf出现warning C4997: 'sprintf': This function or variable may be unsafe.
  10. fr4走线宽度_PCB布线走线宽度变化的影响分析
  11. MFC 小知识总结五
  12. html圆圈里面有数字,HTML + CSS:编号列表与数字圆圈
  13. CSS布局——圣杯布局、双飞翼布局
  14. matlab主成分分析代码
  15. aardio - 利用bitLock快速读写图片颜色值
  16. 元素显示类型-快元素、行内元素、行内快元素、盒子模型以及元素类型相互转换
  17. Linux内核升级(降级)
  18. 教你用Python如何玩转声音文件,将声音按照语音间隙切割为片段
  19. 影视剪辑,自学剪辑的8大技巧
  20. Markdown Reference

热门文章

  1. POJ2104 K-th number 函数式线段树
  2. blog error #include stream.h
  3. 半监督学习价值凸显!谷歌大脑83页PPT介绍最新进展
  4. 值得收藏!动图演示神经架构搜索
  5. 学Python可以用来干什么?就业情况究竟怎么样?
  6. 零基础快速入门python教程,结合新手练习的5大项目
  7. 史上最全AI开源项目集结,近万篇附代码的论文分门别类整理好
  8. MATLAB App Designer GUI开发从0到1(实战篇)
  9. 卷积,特征图,转置卷积和空洞卷积的计算细节
  10. 深度学习(六十六)生成模型、最大化似然、KL散度