Spring boot simultaneously turns on HTTP and HTTPS services

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.