SpringBoot配置HTTPS及开发调试-后端配置

生成HTTPS密钥

keytool -genkeypair -alias tomcat -keyalg RSA -keysize 2048  -ext "SAN=IP:192.168.1.14" -keypass abcd@1234 -keystore frame.jks -storepass abcd@1234 -validity 360000

SAN需要设置你自己电脑的固定ip

配置SSL访问

这里以2.0.0.RELEASE版本为例

server:
  ssl:
  key-store: classpath:systemfile/frame.jks
  key-store-password: abcd@1234
  key-store-type: JKS
  key-alias: tomcat

如果需要打包部署测试环境,需要添加以下配置将jks密钥排除在外

<resources>
      <resource>
         <filtering>true</filtering>
         <directory>src/main/resources</directory>
         <excludes>
              <exclude>**/*.jks</exclude>
         </excludes>
      </resource>
      <resource>
          <filtering>false</filtering>
          <directory>src/main/resources</directory>
          <includes>
               <include>**/*.jks</include>
          </includes>
      </resource>
 </resources>

创建TomcatConfig配置信任

@Configuration
public class TomcatConfig {
    @Bean
    public TomcatServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcatServletContainerFactory = 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);
            }
        };
        tomcatServletContainerFactory.addConnectorCustomizers(new FrameTomcatConnectorCustomizer());
        return tomcatServletContainerFactory;
    }
}
上一篇:PyTorch如何修改模型(魔改)


下一篇:【java数据结构之八大排序(上)-直接插入排序,希尔排序,选择排序,堆排序,向下调整(大根堆,小根堆)等知识详解】-????选择排序