Springboot配置阿里SSL證書Linux部署端口異常

application.yml

http:
  port: 8083

server:
  port: 443
  ssl:
    key-store: classpath:ssl/2788888__xxxxx.com.pfx
    key-store-password: GJH789J
    key-store-type: PKCS12
Application啓動類
// 攔截所有請求
    @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(httpConnector());
        return tomcat;
    }

    // 配置http轉https
    @Bean
    public Connector httpConnector() {
        Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
        connector.setScheme("http");
        // Connector監聽的http的端口號
        connector.setPort(8083);
        connector.setSecure(false);
        // 監聽到http的端口號後轉向到的https的端口號
        connector.setRedirectPort(443);
        return connector;
    }

pom.xml

Linux運行Springboot.jar應用程序,出現以下錯誤:

nohup: ignoring input

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.9.RELEASE)

2020-03-06 22:35:50.376  INFO 1124 --- [           main] com.api.ApiApplication            : Starting ApiApplication v1.0.0 on iZ8vb4ugz9ame9vzmq1t5iZ with PID 1124 (/usr/local/xxx/paymentapi-1.0.0.jar started by root in /usr/local/xxx)
2020-03-06 22:35:50.378  INFO 1124 --- [           main] com.api.ApiApplication            : No active profile set, falling back to default profiles: default
2020-03-06 22:35:51.522  INFO 1124 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8443 (https) 8083 (http)
2020-03-06 22:35:51.541  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Initializing ProtocolHandler ["https-jsse-nio-8443"]
2020-03-06 22:35:51.556  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Initializing ProtocolHandler ["http-nio-8083"]
2020-03-06 22:35:51.565  INFO 1124 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-03-06 22:35:51.565  INFO 1124 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.26]
2020-03-06 22:35:51.648  INFO 1124 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-03-06 22:35:51.648  INFO 1124 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1185 ms
2020-03-06 22:35:52.231  INFO 1124 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-03-06 22:35:52.442  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Starting ProtocolHandler ["https-jsse-nio-8443"]
2020-03-06 22:35:52.613 ERROR 1124 --- [           main] org.apache.catalina.util.LifecycleBase   : Failed to start component [Connector[HTTP/1.1-8443]]

org.apache.catalina.LifecycleException: Protocol handler start failed
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1008)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:227)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:263)
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:195)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:297)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
	at com.api.PaymentapiApplication.main(PaymentapiApplication.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.lang.IllegalArgumentException: Stream closed
	at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:99)
	at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:71)
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:218)
	at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1124)
	at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1210)
	at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:585)
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1005)
	... 22 common frames omitted
Caused by: java.io.IOException: Stream closed
	at java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:67)
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:142)
	at org.springframework.boot.loader.jar.ZipInflaterInputStream.read(ZipInflaterInputStream.java:52)
	at java.io.FilterInputStream.read(FilterInputStream.java:107)
	at org.apache.tomcat.util.security.KeyStoreUtil.load(KeyStoreUtil.java:59)
	at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:217)
	at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:206)
	at org.apache.tomcat.util.net.SSLUtilBase.getKeyManagers(SSLUtilBase.java:283)
	at org.apache.tomcat.util.net.SSLUtilBase.createSSLContext(SSLUtilBase.java:247)
	at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:97)
	... 28 common frames omitted

2020-03-06 22:35:52.613  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Starting ProtocolHandler ["http-nio-8083"]
2020-03-06 22:35:52.628  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Pausing ProtocolHandler ["https-jsse-nio-8443"]
2020-03-06 22:35:52.632  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Pausing ProtocolHandler ["http-nio-8083"]
2020-03-06 22:35:52.640  INFO 1124 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-03-06 22:35:52.644  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Stopping ProtocolHandler ["http-nio-8083"]
2020-03-06 22:35:52.647  INFO 1124 --- [           main] org.apache.catalina.util.LifecycleBase   : The stop() method was called on component [StandardServer[-1]] after stop() had already been called. The second call will be ignored.
2020-03-06 22:35:52.648  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Stopping ProtocolHandler ["https-jsse-nio-8443"]
2020-03-06 22:35:52.648  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Destroying ProtocolHandler ["https-jsse-nio-8443"]
2020-03-06 22:35:52.648  INFO 1124 --- [           main] o.a.coyote.http11.Http11NioProtocol      : Destroying ProtocolHandler ["http-nio-8083"]
2020-03-06 22:35:52.651  INFO 1124 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-06 22:35:52.652 ERROR 1124 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8443 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8443, or configure this application to listen on another port.

2020-03-06 22:35:52.655  INFO 1124 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

注意:

1.換任意空閒端口都會出現此問題

2.將SSL配置註釋後,運行正常

 

錯誤原因:

在Spring 2.1.9.RELEASE中,Tomcat 9.0.26似乎是一個問題 。

降低Tomcat版本

Springboot修改內置Tomcat版本

 

此問題真的是讓我幾乎崩潰啊,瘋掉的感覺

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章