Since the HTTPS service is more complex to turn on in spring boot, it is officially recommended to turn on the HTTP service by encoding, while the HTTPS service is turned on by configuration.
Add the following configuration to the Spring boot application.yml to turn on the HTTPS service
server:port:16062ssl:key-store:classpath:config/test.jkskey-store-password:123456key-password:123456
The JKS certificate file can be generated using the JDK tool Keytool.exe (in the JDK bin directory):
Keytool-genkeypair-alias test-keyalg rsa-validity 3650-keystore Test.jks
To verify the certificate that was generated in the previous step:
Keytool-list-v-keystore Test.jks
To export a public key certificate (optional):
Keytool-export-alias Test-keystore Test.jks-rfc-file Test.cer
After configuring the public key certificate as a trusted certificate on the guest operating system, you can eliminate the HTTPS warning that the browser generates because it cannot verify the authenticity of the certificate that was issued privately.
Write the following code in Application.java to turn on the HTTP service
@SpringBootApplication Public classsampletomcattwoconnectorsapplication {@Bean PublicInteger Port () {returnSocketutils.findavailabletcpport (); } @Bean Publicembeddedservletcontainerfactory Servletcontainer () {tomcatembeddedservletcontainerfactory tomcat=Newtomcatembeddedservletcontainerfactory (); Tomcat.addadditionaltomcatconnectors (Createstandardconnector ()); returnTomcat; } PrivateConnector Createstandardconnector () {Connector Connector=NewConnector ("Org.apache.coyote.http11.Http11NioProtocol"); Connector.setport (port ()); returnconnector; } Public Static voidMain (string[] args)throwsException {springapplication.run (sampletomcattwoconnectorsapplication.class, args); }}
Spring boot simultaneously turns on HTTP and HTTPS services