Using Gradle to build Springboot Engineering series: Sixth: Springboot replace Tomcat as jetty or undertow_spring-boot

Source: Internet
Author: User

This is the sixth installment of the Spring Boot engineering series using Gradle, and for the rest of the year, we will update the other articles in this series, documenting the process, technical points, and problems encountered in the process of building the Spring boot project using Gradle. Welcome to the Program Ape common attention to learning, but also welcome everyone to shoot bricks, put forward their valuable opinions, knowledge in the exchange of collisions, technology in the exchange of Ascension.
By introducing the previous article, we know that the default inline tomcat in spring boot is the servlet container component, which is one of the technical highlights that Springboot has for us, so that we can direct our application into a jar package and deploy directly on the server system, Instead of making the application a war package as before, and then deploying it into a separate Tomcat container, we can save the running resources of the physical server and simplify a lot of work for the operations staff.
Sometimes we don't want to use Tomcat as our servlet container plug-in because of the use of custom or the requirements of the project team. At this time we only need to modify the relevant configuration in the Build.gradle and refresh the project dependencies, we can achieve the switch of container components, because Springboot has encapsulated the current more popular container components, here only the jetty and Undertow, Other container components supported by spring boot can be looked up in the library and introduced in a way similar to the introduction described in this article.

To be replaced by jetty:

Find dependencies code slices, introduce jetty dependencies,

dependencies {
    compile (
            ' org.springframework.boot:spring-boot-starter-actuator ',
            ' Org.springframework.boot:spring-boot-starter-web ',
            ' Org.springframework.boot:spring-boot-starter-jetty '
    )
    Testcompile (' Org.springframework.boot:spring-boot-starter-test ')
}

Refreshing project dependencies, Gradle will automatically download the jetty dependent packages for us:

By the time we restart the Spring boot project, we can see in the console the information that has been exported jetty, indicating that we have successfully replaced Tomcat with jetty:

To be replaced by Undertow:

In the same way as replacing jetty, just update the dependent dependencies in the code slice to undertow.

dependencies {
    compile (
            ' org.springframework.boot:spring-boot-starter-actuator ',
            ' Org.springframework.boot:spring-boot-starter-web ',
            * * * Org.springframework.boot: Spring-boot-starter-undertow ' * * *
    testcompile (' org.springframework.boot:spring-boot-starter-test ')
}

Refresh the dependencies again and restart the project, and we can also see the console has updated the container information to Undertow:

Summarize
In this article, we have implemented the Springboot default servlet container from Tomcat to jetty, then to Undertow, in the next article we will introduce database access, introduce RABBITMQ, introduce mybatis, introduce system monitoring, Privilege management and other common system functions, as well as through SPRINGMVC to rest WebService implementation, welcome attention.

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.