Spring Boot uses jetty as the default Web container _spring

Source: Internet
Author: User
It takes only two steps to replace the default Web container in Springboot as jetty

Step One: Remove the default tomcat dependencies in the Springboot.

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId> spring-boot-starter-web</artifactid>
            <exclusions>
                <exclusion>
                    <groupId> Org.springframework.boot</groupid>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Step Two: Add jetty dependencies.

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId> Spring-boot-starter-jetty</artifactid>
        </dependency>

Completing the POM file:

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupid>com.chin A.test</groupid> <artifactId>springboot-web</artifactId> <version>0.0.1-snapshot</ version> <packaging>jar</packaging> <name>springboot-web</name> <description&gt ;D Emo project for Spring boot</description> <parent> <groupid>org.springframework.boot</ Groupid> <artifactId>spring-boot-starter-parent</artifactId> &LT;VERSION&GT;1.5.8.RELEASE&L T;/version> <relativePath/> <!--lookup parent from repository--> </parent> <pro Perties> <project.build.sourceEncoding>Utf-8</project.build.sourceencoding> <project.reporting.outputencoding>utf-8</ Project.reporting.outputencoding> <java.version>1.8</java.version> </properties>
            ;d ependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusi On> <groupId>org.springframework.boot</groupId> <artifactid>s pring-boot-starter-tomcat</artifactid> </exclusion> </exclusions> &L
            T;/dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <
 /dependency> <dependency>           <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-jetty
            </artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> &LT;ARTIFAC 


tid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build>
 </project>

Project Launch results show:

---: jetty-9.4.7.v20170914
---: Defaultsessionidmanager workername=node0
---: No sessionscavenger set, using D Efaults
---: scavenging every 660000ms
---: Initializing Spring embedded Webapplicationcontext
---: Root We Bapplicationcontext:initialization completed in 4275 MS
---: Mapping servlet: ' Dispatcherservlet ' to [/]
---: M Apping filter: ' Characterencodingfilter ' to: [/*]
---: Mapping filter: ' Hiddenhttpmethodfilter ' to: [* *]
---: Ma Pping filter: ' Httpputformcontentfilter ' to: [/*]
---: Mapping filter: ' Requestcontextfilter ' to: [/*]
---: Sta RTed o.s.b.c.e.j.jettyembeddedwebappcontext@7555b920{/,[file:///c:/users/jetty/appdata/local/temp/ Jetty-docbase.966869451084382807.8080/],available}
---: Started @6207ms
--- 
---: Started SERVERCONNECTOR@4152D38D{HTTP/1.1,[HTTP/1.1]}{0.0.0.0:8080}
---: Jetty started on port (s) 8080 (http/1.1)
---: Started springbootwebapplication in 7.023 seconds (JVM running for 7.909)

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.