SpringBoot配置阿里云https提示端口占用问题

1.因为要配置https,所以去网上找了一些资料,然后按照步骤,依次完成了以下步骤

①在application.yml中加入配置

http:
port: 12000 #原本的端口号
server:
port: 443
ssl:
key-store: classpath:key.pfx #阿里云的证书,放到resources目录下,引用
key-store-password: FvDFDNtDDD9 #阿里云连同证书一块下载下来的密码
keyStoreType: PKCS12



②在启动项添加如下配置
@Bean
public ServletWebServerFactory servletContainer() {
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(redirectConnector());
return tomcat;
}

private Connector redirectConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(12000);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}



③随后启动
问题就在这,我看别人都是直接启动成功了,我这边就老是报443端口占用,哪怕我换成其他的端口,也是疯狂的报新端口被占用,然后开始了我的找答案过程

解决方案一:找到占用端口的进程,先执行netstat -aon | findstr "443",然后看看有没有被占用,找到了的话再根据pid找到占用的进程是什么(tasklist | findstr "8144"),关闭这个进程即可.

我试了第一种方案,对我这边无效,于是继续自己摸索

然后,然后我就发现我的那个阿里云文件名有点长,还带下划线那种,我就想,会不会是因为解析冲突了,类似于文件not found那种,抱着试试的心态,
我把文件名改成了一个简单的,如下,图一是原来的下载下来的文件名,老是报端口占用

 

 

然后图二是我改了文件名之后的,注意这里,虽然大佬应该都知道,但是如果已经到了怀疑人生的地步,可能脑子会懵

先把resources下你从阿里云下载下来的文件改成一个简单的英文字母的文件,例如我就直接命名为:key

 

 然后再改application.yml的配置,改成对应的名字

 

 然后再尝试启动,运气好的话,你就会像我一样,成功启动了,那么,祝你好运!

posted on 2019-12-23 13:49  必经之路  阅读(2092)  评论(0编辑  收藏  举报

导航