• springboot设置Https请求


    1.首先去阿里云购买个证书,也有免费的,但是免费的只能使用一年,证书需要绑定域名

    2.将证书放进项目

    3.配置YML

    server:
    ssl:
    key-store: 55555.pfx
    key-store-password: 55555
    keyStoreType: PKCS12
    connectionTimeout: 20000
    port: 8888

    重点来了,配置请求转发

    @Configuration
    public class WebMvcconfig implements WebMvcConfigurer {

    @Bean
    public TomcatServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
    @Override
    protected void postProcessContext(Context context) {
    SecurityConstraint constraint = new SecurityConstraint();
    constraint.setUserConstraint("CONFIDENTIAL");
    SecurityCollection collection = new SecurityCollection();
    collection.addPattern("/*");
    constraint.addCollection(collection);
    context.addConstraint(constraint);
    }
    };
    tomcat.addAdditionalTomcatConnectors(httpConnector());
    return tomcat;
    }

    @Bean
    public Connector httpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    // Connector监听的http的端口号
    connector.setPort(8080);
    connector.setSecure(false);
    // 监听到http的端口号后转向到的https的端口号
    connector.setRedirectPort(8888);
    return connector;
    }
    }

    如果请求报错:java.lang.UnsatisfiedLinkError: org.apache.tomcat.jni.SSL.renegotiatePending(J)I问题

    在pom.xml中加入

      <properties>
            <tomcat.version>9.0.12</tomcat.version>
        </properties>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-juli</artifactId>
                <version>${tomcat.version}</version>
            </dependency>

    然后运行,请求成功!

  • 相关阅读:
    DNS原理总结及其解析过程详解
    linux修改进程名
    mq_open失败,Invalid argument
    Posix消息队列
    undefined reference to 'mq_open'
    量化投资学习笔记08——统计学基础补漏
    量化投资学习笔记07——python知识补漏
    量化投资学习笔记06——《打开量化投资的黑箱》读书笔记
    量化投资学习笔记05——检验计算回测指标程序
    量化投资学习笔记04——回测实盘策略
  • 原文地址:https://www.cnblogs.com/wiliamzhao/p/13234231.html
Copyright © 2020-2023  润新知