• 大小: 124KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: Java
  • 标签: java  spring  https  

资源简介

java开发 微信小程序支付接口的demo; 使用springboot 进行编写,maven搭建的项目,调用官方的sdk 和自己编写的代码 demo中含有https映射配置讲解

资源截图

代码片段和文件信息

package com.majker;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class QuickStartApplication {

    public static void main(String[] args) {
        // 程序启动入口
        // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
        SpringApplication.run(QuickStartApplication.class args);
    }

    @Bean
    public Connector connector(){
        Connector connector=new Connector(“org.apache.coyote.http11.Http11NioProtocol“);
        connector.setScheme(“http“);
        connector.setPort(8081);
        connector.setSecure(false);
        connector.setRedirectPort(8443);
        return connector;
    }

    @Bean
    public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector){
        TomcatServletWebServerFactory tomcat=new TomcatServletWebServerFactory(){
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint securityConstraint=new SecurityConstraint();
                securityConstraint.setUserConstraint(“CONFIDENTIAL“);
                SecurityCollection collection=new SecurityCollection();
                collection.addPattern(“/*“);
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(connector);
        return tomcat;
    }

}

评论

共有 条评论