Springboot开启APR模式

下载

在Springboot中内嵌的Tomcat默认启动开启的是NIO模式,这里如果我们要在linux内核的系统上使用APR模式,那么需要安装一些lib库,可以通过rpm -q | grep apr来查看是否安装了apr,如果安装了则不再需要安装,如果未安装则需要安装下列库:

1.openssl,需要版本大于1.0.2,如果不使用https openssl也可以不安装,就是在启动的时候会报openssl的错误,直接忽视就可以了;

2.apr,可以去官网下载1.6.2最新版进行下载 http://apr.apache.org/download.cgi

3.apr-util,在同一个页面进行下载,最新版本为1.6.0版本

4.apr-iconv,在同一个页面进行下载,最新版本为1.2.1版本

5.tomcat-native,在tomcat中自带了安装包,可以在tomcat的bin目录下找到tomcat-native.tar;

安装apr

下载apr安装包apr-1.6.2.tar.gz

tar -xvf apr-1.6.2.tar.gz

cd apr-1.6.2

./configure 检查是否符合安装条件并配置安装参数,检查是否缺失类库,一般来说如果安装的不是精简版系统都是能顺利通过的

make & make install

如果不设置安装路径,那么系统默认的安装路径为/usr/local/apr/lib

安装apr-util

下载apr-util安装包apr-util-1.6.0.tar.gz

tar -xvf apr-util-1.6.0.tar.gz

cd apr-util-1.6.0
./configure --with-apr=/usr/local/apr/lib --with-java-home=/usr/lib/jvm/jdk-8u144-linux-x64/jdk1.8.0_144 
安装apr-util需要配置apr路径和jvm路径,否则会报错找不到apr
make & make install

安装apr-iconv

下载apr-iconv.tar.gz

tar -xvf apr-iconv.tar.gz
cd apr-iconv
./configure --with-apr=/usr/local/apr/lib --with-java-home=/usr/lib/jvm/jdk-8u144-linux-x64/jdk1.8.0_144
make & make install

安装tomcat-native

cd tomcat/bin
tar -xvf tomcat-native
cd tomcat-native
./configure --with-apr=/usr/local/apr/lib --with-java-home=/usr/lib/jvm/jdk-8u144-linux-x64/jdk1.8.0_144
make & make install

配置apr

vi /etc/profile

在profile最前面加上 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr-1.6.2/lib

命令行输入 source /etc/profile 使之生效

新增APRConfig类

import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.AprLifecycleListener;
import org.springframework.beans.factory.annotation.Value;
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;

/**
 * @Author: feiweiwei
 * @Description: APR配置
 * @Created Date: 09:23 17/9/7.
 * @Modify by:
 */
@Configuration
public class APRConfig {
    @Value("${tomcat.apr:false}")
    private boolean enabled;

    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
        if (enabled) {
            LifecycleListener arpLifecycle = new AprLifecycleListener();
            container.setProtocol("org.apache.coyote.http11.Http11AprProtocol");
            container.addContextLifecycleListeners(arpLifecycle);
        }

        return container;
    }
}

启动

java -Djava.library.path=/usr/apr/lib -jar xxxx-0.0.1-SNAPSHOT.jar 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梁晓山(ben)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值