重定向发布方法HTTP-> HTTPS-HTTP状态405(spring启动)

重定向发布方法HTTP-> HTTPS-HTTP状态405(spring启动),第1张

重定向发布方法HTTP-> HTTPS-HTTP状态405(spring启动)

摆弄了多个教程后,答案是遵循官方指南…

http://docs.spring.io/spring-boot/docs/current-
SNAPSHOT/reference/htmlsingle/#howto-enable-multiple-connectors-in-
tomcat

更新:

import org.apache.catalina.connector.Connector;import org.apache.coyote.http11.Http11NioProtocol;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import java.io.File;@Configurationpublic class HttpsConnector {    @Value("${cert.keyStore}")    private String keyStorePath;    @Value("${cert.trustStore}")    private String trustStorePath;    @Value("${cert.keyStorePass}")    private String keyStorePass;    @Value("${cert.trustStorePass}")    private String trustStorePass;    @Value("${cert.keyStoreType}")    private String keyStoreType;    @Value("${cert.trustStoreType}")    private String trustStoreType;    @Value("${cert.keyAlias}")    private String keyAlias;    @Value("${cert.httpsPort}")    private int httpsPort;    @Bean    public EmbeddedServletContainerFactory servletContainer() {        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();        tomcat.addAdditionalTomcatConnectors(createSslConnector());        return tomcat;    }    private Connector createSslConnector() {        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();        String absKeyStorePath = getAbsolutePath(keyStorePath);        String absTrustStorePath = getAbsolutePath(trustStorePath);        connector.setScheme("https");        connector.setSecure(true);        connector.setPort(httpsPort);        protocol.setSSLEnabled(true);        protocol.setKeystoreType(keyStoreType);        protocol.setKeystoreFile(absKeyStorePath);        protocol.setKeystorePass(keyStorePass);        protocol.setTruststoreType(trustStoreType);        protocol.setTruststoreFile(absTrustStorePath);        protocol.setTruststorePass(trustStorePass);        protocol.setKeyAlias(keyAlias);        return connector;    }    private String getAbsolutePath(String path) {        File file = new File(path);        if (!file.isAbsolute()) { path = file.getAbsolutePath();        }        return path;    }}

组态

#SERVER CONFIGserver.port=8090#Certificatecert.keyStore=src/main/resources/keystore.p12cert.trustStore=src/main/resources/keystore.p12cert.keyStorePass=...cert.trustStorePass=...cert.keyStoreType=pkcs12cert.trustStoreType=pkcs12cert.keyAlias=...cert.httpsPort=8443


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5506803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存