基于springboot设置Https请求过程解析

网友投稿 476 2023-05-03

基于springboot设置Https请求过程解析

基于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中加XHPmkVWeoz入

9.0.12

org.apache.tomcat

tomcat-juli

${tomcat.version}

然后运行,请求成功!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Springboot前后端分离项目配置跨域实现过程解析
下一篇:idea日志乱码和tomcat日志乱码问题的解决方法
相关文章

 发表评论

暂时没有评论,来抢沙发吧~