spring-boot项目启动失败的一种解决办法:自带的tomcat容器切换成jetty容器
来源:互联网 发布:国家统计局2016年数据 编辑:程序博客网 时间:2024/05/20 00:16
按照spring-boot官方的demo例子好像搭建一个spring-boot工程非常简单,但是环境的差异导致工程启动失败,这却让人异常蛋疼!
比如刚开始使用下面这个配置启动就挂了,在自己本地环境启动直接失败报红叉:
spring-boot使用自带tomcat容器的配置:
<dependencies> <!-- spring-boot使用自带tomcat容器配置begin --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-juli</artifactId> <version>1.8</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>1.5.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>1.5.3.RELEASE</version> <scope>test</scope> </dependency> <!-- spring-boot使用自带tomcat容器配置end --></dependencies>
由于上面的配置使用的容器是spring-boot自带的tomcat容器,导致启动报错:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: org/apache/catalina/SessionIdGenerator 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.example.demo.DemoApplication.main(DemoApplication.java:13) [classes/:na]Caused by: java.lang.NoClassDefFoundError: org/apache/catalina/SessionIdGenerator at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.java:192) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:178) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[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 omittedCaused by: java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:37) ~[tomcat-embed-core-7.0.53.jar:7.0.53] at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:169) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[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 omittedCaused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_101] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_101] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_101] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_101] ... 12 common frames omitted
在度娘上搜了一圈,spring-boot启动的这些异常,有些说是tomcat版本冲突的问题所致,但查看我的spring工程,tomcat版本没有问题,调试了一圈,搞的晕头转向,最后干脆不搞tomcat,直接改用jetty算了!
解决办法:使用嵌入式jetty作为web容器解决这些问题,省事又省心(根据项目需要选择jetty或者tomcat最为web容器)
<dependencies> <!-- spring-boot使用jetty容器配置begin --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- 排除默认的tomcat,引入jetty容器. --> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- jetty 容器. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- spring-boot使用jetty容器配置end --></dependencies>
至于jetty容器与tomcat容器的特性和优缺点,请自行度娘了解!
阅读全文
0 0
- spring-boot项目启动失败的一种解决办法:自带的tomcat容器切换成jetty容器
- Spring Boot 使用 jetty 作为默认的Web容器
- Spring-boot 配置Jetty 容器
- Tomcat Jetty容器中部署项目的注意事项与区别
- spring-boot项目按照平常的web项目一样发布到tomcat容器下
- Servlet容器:Jetty和tomcat的比较
- spring boot项目发布tomcat容器(包含发布到tomcat6的方法)
- Spring boot项目Tomcat启动与切换
- Spring Boot部署至自己的Tomcat容器
- spring boot修改内置容器tomcat的服务端口
- Spring Boot 定制与优化内置的Tomcat容器
- Spring自带的几种容器实现
- springboot内嵌容器的tomcat和jetty的切换原理
- 选择Spring Boot项目的内嵌容器
- 选择Spring Boot项目的内嵌容器
- 把spring-boot项目部署到tomcat容器中
- spring-boot项目部署到tomcat容器中
- 把spring-boot项目部署到tomcat容器中
- 2017年澳洲建筑师协会奖入围作品:办公空间
- 学习笔记
- 使用sharedPreferences实现密码登录和注册用户名重复检查
- NOI 2017 机房酱油记
- 位运算面试题常用技巧
- spring-boot项目启动失败的一种解决办法:自带的tomcat容器切换成jetty容器
- 海量数据文本相似度解决方式SimHash+分词方法+基于内容推荐算法
- Java:基础练习-循环练习
- jquery 给文本框赋值
- Android ADT代码提示问题
- Delphi遍历进程并获取进程路径
- C++和Matlab混合编程——MATLAB调用c++函数(以svmlight为例)
- Magento清空购物车
- 中国哪些城市最具有房产投资前景?