基于springboot设置Https请求过程解析
1.首先去阿里云购买个证书,也有免费的,但是免费的只能使用一年,证书需要绑定域名
2.将证书放进项目
3.配置YML
server: ssl: key-store: 55555.pfx key-store-password: 55555 keyStoreType: PKCS12 connectionTimeout: 20000 port: 8888
重点来了,配置请求转发
@Configurationpublic 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>
然后运行,请求成功!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持好吧啦网。
相关文章:
1. IntelliJ IDEA设置背景图片的方法步骤2. CentOS邮箱服务器搭建系列——SMTP服务器的构建( Postfix )3. IIS Express 取代 ASP.NET Development Server的配置方法4. idea给项目打war包的方法步骤5. IntelliJ IDEA恢复删除文件的方法6. 排查Java应用内存泄漏问题的步骤7. 自从在 IDEA 中用了热部署神器 JRebel 之后,开发效率提升了 10(真棒)8. Java 3D显示3D物体9. 解决运行django程序出错问题 'str'object has no attribute'_meta'10. idea配置jdk的操作方法

网公网安备