• springboot整合jetty(转)


    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替换容器在网上搜索只需要两步

    <!-- web剔除tomcat容器= -->
    <parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>1.5.10.RELEASE</version>
     <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <groupId>org.springframework.boot</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- 引入Jetty容器-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

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

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

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

     @Configuration
        @ConditionalOnClass({ Servlet.class, Server.class, Loader.class,
                WebAppContext.class })
        @ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT)
        public static class EmbeddedJetty {
     
            @Bean
            public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
                return new JettyEmbeddedServletContainerFactory();
            }
        }

    手动注入Jetty容器工厂

    启动

    package com.liuhao.study.config;
     
    import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
     
    /**
     * @Author: liuhao
     * @Date: 2018/10/31 13:58
     * @Description:
      **/
    @Configuration
    public class JettyConfiguration {
     
        @Bean
      public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
            return new JettyEmbeddedServletContainerFactory();
      }
    }

    继续报错

    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
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
        ... 19 common frames omitted
    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

  • 相关阅读:
    超链接标签、链接地址、锚文本及图片标签
    有序无序列表,div盛放逻辑版块,table表格
    函数的默认值与动态参数arguments的总结
    浏览器中常见的html语义化标签
    html基本介绍,了解html与css,html语法和结构
    js函数与作用域,了解函数基本概念
    JavaScrip流程控制之switch选择,for循环
    JavaScript之if流程控制演练,if写在区间内怎么解决
    JavaScript数据类型typeof()和转换
    C++走向远洋——60(十四周阅读程序、STL中的简单容器和迭代器)
  • 原文地址:https://www.cnblogs.com/muxi0407/p/11812335.html
Copyright © 2020-2023  润新知