jdk1.8 springboot替换容器在网上搜索只需要两步
如果不是可能就会报错Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
手动注入Jetty容器工厂
解决方法:
方法一:降低springboot版本到1.3.8,缺点:1.3.8和1.5.x配置升级很大不同,降低版本兼容不合适
方法二:升级jdk1.8,考虑目前开发环境都是1.7,缺点也不合适
方法三:手动指定jetty版本为jdk1.7版本

jdk1.8 springboot替换容器在网上搜索只需要两步

  1. <!-- web剔除tomcat容器= -->
  2. <parent>
  3.  <groupId>org.springframework.boot</groupId>
  4.  <artifactId>spring-boot-starter-parent</artifactId>
  5.  <version>1.5.10.RELEASE</version>
  6.  <relativePath/> <!-- lookup parent from repository -->
  7. </parent>
  8. <dependency>
  9.     <groupId>org.springframework.boot</groupId>
  10.     <artifactId>spring-boot-starter-web</artifactId>
  11.     <exclusions>
  12.         <exclusion>
  13.             <artifactId>spring-boot-starter-tomcat</artifactId>
  14.             <groupId>org.springframework.boot</groupId>
  15.         </exclusion>
  16.     </exclusions>
  17. </dependency>
  18. <!-- 引入Jetty容器-->
  19. <dependency>
  20.     <groupId>org.springframework.boot</groupId>
  21.     <artifactId>spring-boot-starter-jetty</artifactId>
  22. </dependency>

如果你是jdk1.8版本
启动正常!

如果不是可能就会报错Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

  1. 2017-03-18 17:03:23.212 ERROR 11488 --- [main] o.s.boot.SpringApplication : Application startup failed
  2. 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.

报错的原因是EmbeddedServletContainerAutoConfiguration没有自动加载Jetty容器
但是ConditionOnClass的类都满足,没有办法只有手动注入一个EmbeddedServletContainerFactory对应Jetty的实现

  1. @Configuration
  2. @ConditionalOnClass({ Servlet.class, Server.class, Loader.class,
  3. WebAppContext.class })
  4. @ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT)
  5. public static class EmbeddedJetty {
  6.  
  7. @Bean
  8. public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
  9. return new JettyEmbeddedServletContainerFactory();
  10. }
  11. }

手动注入Jetty容器工厂

启动

  1. package com.liuhao.study.config;
  2.  
  3. import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6.  
  7. /**
  8. * @Author: liuhao
  9. * @Date: 2018/10/31 13:58
  10. * @Description:
  11. **/
  12. @Configuration
  13. public class JettyConfiguration {
  14.  
  15. @Bean
  16. public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
  17. return new JettyEmbeddedServletContainerFactory();
  18. }
  19. }

继续报错

  1. Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory]: Factory method 'jettyEmbeddedServletContainerFactory' threw exception; nested exception is java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0
  2. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
  3. at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
  4. ... 19 common frames omitted
  5. Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0

原因:
Caused by: java.lang.UnsupportedClassVersionError: org/eclipse/jetty/webapp/WebAppContext : Unsupported major.minor version 52.0这个错误是一个典型的jdk版本不匹配导致的错误

解决方法:
知道了问题是因为jetty版本和jdk版本不匹配不一致导致的就很好解决了
springboot使用的版本是1.5.10.RELEASE,jetty的版本是9.4.8.v20171121,需要jdk1.8环境

方法一:降低springboot版本到1.3.8,缺点:1.3.8和1.5.x配置升级很大不同,降低版本兼容不合适
方法二:升级jdk1.8,考虑目前开发环境都是1.7,缺点也不合适
方法三:手动指定jetty版本为jdk1.7版本
<jetty.version>9.2.12.v20150709</jetty.version>
sprinboot-整合jetty jdk1.7项目地址:
https://github.com/harryLiu92/springboot-study/tree/master/springboot-jetty
————————————————
版权声明:本文为CSDN博主「熏肉大饼」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w5167839/article/details/83585970

springboot整合jetty(转)的更多相关文章

  1. springboot整合jetty

    1.jetty介绍 通常我们进行Java Web项目开发,必须要选择一种服务器来部署并运行Java应用程序,Tomcat和Jetty作为目前全球范围内最著名的两款开源servlet容器,该怎么选呢. ...

  2. SpringBoot系列六:SpringBoot整合Tomcat

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合 Tomcat 2.背景 SpringBoot 本身支持有两类的 WEB 容器:默认的 To ...

  3. Springboot以Jetty为容器实现http重定向到https

    1 简介 之前讲解的Springboot整合https用的是tomcat作为容器,tomcat也是一个流行多年的老牌Java容器了.但针对不同的场景,还是会有不同的选择,如Jetty.Jetty是架构 ...

  4. Https双向验证与Springboot整合测试-人来人往我只认你

    1 简介 不知不觉Https相关的文章已经写了6篇了,本文将是这个专题的最后一篇,起码近期是最后一篇.前面6篇讲的全都是单向的Https验证,本文将重点介绍一下双向验证.有兴趣的同学可以了解一下之前的 ...

  5. spring-boot整合mybatis(1)

    sprig-boot是一个微服务架构,加快了spring工程快速开发,以及简便了配置.接下来开始spring-boot与mybatis的整合. 1.创建一个maven工程命名为spring-boot- ...

  6. SpringBoot整合Mybatis之项目结构、数据源

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  7. springboot整合mq接收消息队列

    继上篇springboot整合mq发送消息队列 本篇主要在上篇基础上进行activiemq消息队列的接收springboot整合mq发送消息队列 第一步:新建marven项目,配置pom文件 < ...

  8. springboot整合mybaits注解开发

    springboot整合mybaits注解开发时,返回json或者map对象时,如果一个字段的value为空,需要更改springboot的配置文件 mybatis: configuration: c ...

  9. SpringBoot整合Redis、ApachSolr和SpringSession

    SpringBoot整合Redis.ApachSolr和SpringSession 一.简介 SpringBoot自从问世以来,以其方便的配置受到了广大开发者的青睐.它提供了各种starter简化很多 ...

随机推荐

  1. Sliding Puzzle

    On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square repre ...

  2. 【转帖】Office的光荣历史(2)

    Office的光荣历史(2) https://www.sohu.com/a/201411215_657550 2017-10-31 10:57 7.MS Office 2000 (Office 9.0 ...

  3. SOSdp

    layout: post title: SOSdp author: "luowentaoaa" catalog: true tags: mathjax: true - codefo ...

  4. PyCharm 格式化代码 常用快捷键

    ctrl+alt+L 一 常用快捷键 编辑类:Ctrl + D             复制选定的区域或行Ctrl + Y           删除选定的行Ctrl + Alt + L     代码格 ...

  5. 怎样在 Vue 的 component 组件中使用 props ?

    1. 在注册一个组件时, 添加一个 props 属性, 将需要添加的 props 作为数组的元素进行添加, 比如下面的例子中, 我们添加了一个变量 name , 他就是一个 props, 我们可以通过 ...

  6. java写webservice接口

    有一个需求:要求根据设备mac和终端设备类型来查询设备库存状态. 接口协议是采用webservice协议,信息交互方式为xml格式信息 输入参数存放到XML各个节点下,并转为一个String,作为接口 ...

  7. 转:Git和Github简单教程

    转自:https://www.cnblogs.com/schaepher/p/5561193.html Git和Github简单教程   原文链接:Git和Github简单教程 网络上关于Git和Gi ...

  8. Redis-ZSet常用命令

    Redis-ZSet常用命令 zadd key score member[{score member}-] 创建或设置指定key对应的有序集合,根据每个值对应的score来排名,升序.例如有命令 za ...

  9. JDBC及PreparedStatement防SQL注入

    概述 JDBC在我们学习J2EE的时候已经接触到了,但是仅是照搬步骤书写,其中的PreparedStatement防sql注入原理也是一知半解,然后就想回头查资料及敲测试代码探索一下.再有就是我们在项 ...

  10. /etc/ld.so.conf.d/目录下文件的作用

    在了解/etc/ld.so.conf.d/目录下文件的作用之前,先介绍下程序运行是加载动态库的几种方法: 第一种,通过ldconfig命令     ldconfig命令的用途, 主要是在默认搜寻目录( ...