SpringBoot 2.x is configured ssl tomcat (https) support

Reference Source: https://www.cnblogs.com/imfjj/p/9058443.html

https://blog.csdn.net/jackymvc/article/details/81077885

Configure the certificate:

keytool -genkeypair -alias tomcat -keyalg RSA -keystore tomcat.key

Fill in the following order:

mcat.key 
Enter keystore password: 
Enter the new password again: 
What is your first name and last name ? 
  [Unknown]: localhost 
what your organizational unit name ? 
  [Unknown]: localhost 
What is your organization name ? 
  [Unknown] : xxx Co, .Ltd 
your city or region name what is ? 
  [Unknown]: kunshan 
province you are in what / city / autonomous regions name? 
  [Unknown]: SuZhou 
two-letter country this unit what / area code? 
  [Unknown]: China 
the CN = localhost, the OU = localhost, O = " xxxCo, .Ltd " , L = kunshan, ST = SuZhou, C = Chin 
a correct ? 
  [NO]: y 

enter <tomcat> key password  
        (If the same password and key store, press Enter):
enter the new password again:

To generate certificates in the resources directory

Configuration application.yml

debug: true
server:
  port: 8110
  tomcat:
    max-threads: 800
    accept-count: 30000
    min-spare-threads: 20
    max-connections: 30000
  ssl:
    key-store: classpath:tomcat.key
    key-store-type: JKS
    key-alias: tomcat
    #证书密码
    key-store-password: xxxx

Halfway encountered error:

2019-09-09 08:43:49.752 default [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException: Connector configured to listen on port 8110 failed to start
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.checkThatConnectorsHaveStarted(TomcatWebServer.java:228)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:203)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162)
    at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:553)
    at org.springframework.context.support.AbstractApplicationContext.jrLockAndRefresh(AbstractApplicationContext.java:40002)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:41008)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
    at com.netmarch.web.WebApplication.main(WebApplication.java:34)
2019-09-09 08:43:49.752 default [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 

Solution:

参考来源:Spring Boot- The Tomcat connector configured to listen on port 8080 failed to start

SpringBoot 2.x

Add a component class

import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;

@Component
public class CustomContainer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

    @Override
    public void customize(ConfigurableServletWebServerFactory factory) {

        factory.setPort(8110);
    }
}

 SpringBoot 1.x Solution:

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.Component;

@Component
public class CustomContainer implements EmbeddedServletContainerCustomizer {

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {

        container.setPort(8085);

    }

}

 

Guess you like

Origin www.cnblogs.com/passedbylove/p/11489686.html