Spring Boot切换为APR模式
Spring Boot内置了tomcat容器,直接运行Application就可以启动web服务器。
在tomcat中提供了三种方式:BIO、NIO、APR。
BIO
tomcat7以下的版本都是BIO,就是一个请求是一个独立的线程。不能适用高并发的场景。
NIO
在8以上的版本,默认都是NIO
APR
APR是一种基于JNI的文件和网络读写模式,现在很多高版本的tomcat,都默认走它了。
在tomcat中配置,很好配置,直接修改protocol就可以了。但是在spring boot中,配置是在Java代码中写的。
下面是配置的代码:
import org.apache.catalina.core.AprLifecycleListener;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class APRConfig {
// https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/htmlsingle/#howto-discover-build-in-options-for-external-properties
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.setProtocol("org.apache.coyote.http11.Http11AprProtocol");
tomcat.addContextLifecycleListeners(new AprLifecycleListener());
return tomcat;
}
}
配置完启动,有可能会报错:
2018-06-06 16:21:44,891 [main] ERROR org.apache.catalina.core.StandardService:181 - Failed to start connector [Connector[org.apache.coyote.http11.Http11AprProtocol-8104]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[org.apache.coyote.http11.Http11AprProtocol-8104]]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:250)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:193)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at xxx.Application.main(Application.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: org.apache.catalina.LifecycleException: The configured protocol [org.apache.coyote.http11.Http11AprProtocol] requires the APR/native library which is not available
at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
... 22 common frames omitted
此时你需要在启动spring boot的服务器上安装tomcat-native和apr的模块。可以参考下面的参考文章
参考
Spring Boot切换为APR模式的更多相关文章
- Spring Boot+RabbitMQ 通过fanout模式实现消息接收(支持消费者多实例部署)
本文章适用的场景:同一条消息可以被多个消费者同时消费.注意:当消费者多实例部署时,会轮询消费消息.网上有大量的的案例展示:P生产一条消息,消费者服务C中建立Q1和Q2两个队列共同消费.但极少的材料展示 ...
- Spring boot+Mybatisplus用AR模式实现逻辑删除操作
Mybatisplus的AR模式 Active Record(活动记录),是一种领域模型模式,特点是一个模型类对应关系型数据库中的一个表,而模型类的一个实例对应表中的一行记录.ActiveRecord ...
- Spring boot参考指南
介绍 转载自:https://www.gitbook.com/book/qbgbook/spring-boot-reference-guide-zh/details 带目录浏览地址:http://ww ...
- Spring Boot实战:Restful API的构建
上一篇文章讲解了通过Spring boot与JdbcTemplate.JPA和MyBatis的集成,实现对数据库的访问.今天主要给大家分享一下如何通过Spring boot向前端返回数据. 在现在的开 ...
- 给大家整理了几个开源免费的 Spring Boot + Vue 学习资料
最近抽空在整理前面的文章案例啥的,顺便把手上的几个 Spring Boot + Vue 的学习资料推荐给各位小伙伴.这些案例有知识点的讲解,也有项目实战,正在做这一块的小伙伴们可以收藏下. 案例学习 ...
- Spring Boot & Restful API 构建实战!
作者:liuxiaopeng https://www.cnblogs.com/paddix/p/8215245.html 在现在的开发流程中,为了最大程度实现前后端的分离,通常后端接口只提供数据接口, ...
- spring boot整合RabbitMQ(Direct模式)
springboot集成RabbitMQ非常简单,如果只是简单的使用配置非常少,springboot提供了spring-boot-starter-amqp项目对消息各种支持. Direct Excha ...
- Spring Boot(十三):整合Redis哨兵,集群模式实践
前面的两篇文章(Redis的持久化方案, 一文掌握Redis的三种集群方案)分别介绍了Redis的持久化与集群方案 -- 包括主从复制模式.哨兵模式.Cluster模式,其中主从复制模式由于不能自动做 ...
- 四、Spring Boot 多数据源 自动切换
实现案例场景: 某系统除了需要从自己的主要数据库上读取和管理数据外,还有一部分业务涉及到其他多个数据库,要求可以在任何方法上可以灵活指定具体要操作的数据库.为了在开发中以最简单的方法使用,本文基于注解 ...
随机推荐
- BP神经网络的参数改进参考?
参考文献:黄巧巧. 基于BP神经网络的手写数字识别系统研究[D].华中师范大学,2009. 47-52 BP神经网络的缺陷:收敛速度慢和局部极小点的问题 使用的改进方案有 1. 学习速率(learn ...
- java.io.IOException: java.sql.SQLException: ORA-01502: index 'BTO.PK_xxxxx' or partition of such index is in unusable state
最近由于数据库的全备出问题了,所以一直在观察. 刚好发现很多不需要的数据,就删了几百个G的数据吧. 今天突然就报这个问题. java.io.IOException: java.sql.SQLExcep ...
- Idea中如何将web项目打包成war包并放到tomcat中启动
第一步:在idea中选中Artifacts.右侧勾选Build on make生成war包,如下图 第二步:将target文件夹里面的war包拷贝到tomcat文件下的webapp目录下 第三步:修改 ...
- 2018.12.31 bzoj4001: [TJOI2015]概率论(生成函数)
传送门 生成函数好题. 题意简述:求nnn个点的树的叶子数期望值. 思路: 考虑fnf_nfn表示nnn个节点的树的数量. 所以有递推式f0=1,fn=∑i=0n−1fifn−1−i(n>0) ...
- springboot同时使用thymeleaf和jsp模板
语言:javaEE 框架:springboot+thymeleaf.jsp模板引擎 背景:学习springboot过程中想同时使用thymeleaf和jsp访问(官方不建议) 步骤: 1) 在pom ...
- 系统当前时间system.currenttimemillis与new Date().getTime() 区别
system.currenttimemillis //取到毫秒数,并且执行效率高 new Date().getTime()没他精确
- oracle在exp导出时报错PLS-00201: identifier 'EXFSYS.DBMS_EXPFIL_DEPASEXP' must be declared
报错如下信息: EXP-00008: ORACLE error 6550 encounteredORA-06550: line 1, column 14:PLS-00201: identifier ' ...
- linux-CentOS初学terminal命令(2)vi、gcc、g++、./、mv、cp、ifconfig
1.vi filename(vi,visual editor,可视化编辑器)用vim文本编辑器打开filename文件. vim文本编辑器有三种模式:命令模式(Command mode),插入模式(I ...
- web-day2
第2章WEB02-CSS&JS篇 今日任务 使用CSS完成网站首页的美化 使用CSS完成网站注册页面的美化 使用JS完成简单的数据校验 使用JS完成图片轮播效果 教学导航 教学目标 了解CSS ...
- noip第2课作业
1. 大象喝水 [问题描述] 一只大象口渴了,要喝20升水才能解渴,但现在只有一个深h厘米,底面半径为r厘米的小圆桶(h和r都是整数).问大象至少要喝多少桶水才会解渴. 输入:输入有一行,包行两 ...