Spring-boot Configuration jetty Container _spring related

Source: Internet
Author: User

By default, Spring boot uses the Tomcat container. Sometimes, you might want to use a jetty container instead of Tomcat. Spring boot makes it easy to configure jetty containers by providing jetty starter. Add Spring-boot-starter-jetty Dependencies

Add a configuration if you are using MAVEN.

<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>
<dependency>
< Groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-jetty</ Artifactid>
</dependency>

If you use Gradle, add the following configuration.

Configurations {
    compile.exclude module: "Spring-boot-starter-tomcat"
}

dependencies {
    compile (" Org.springframework.boot:spring-boot-starter-web:2.0.0.build-snapshot ")
    compile (" Org.springframework.boot: Spring-boot-starter-jetty:2.0.0.build-snapshot ")
}
Configure Jetty

Add a configuration to the application.properties to overwrite the jetty default configuration.

server.port=8080
server.servlet.context-path=/home

### #Jetty specific properties########

Server.jetty.acceptors= # acceptor Number of Threads
server.jetty.max-http-post-size=0 # Put or Post method maximum bytes
Server.jetty.selectors= # selector Number of threads

In addition, the Jettyembeddedservletcontainerfactory class can be configured using code.

 @Bean public jettyembeddedservletcontainerfactory jettyembeddedservletcontainerfactory () {

    Jettyembeddedservletcontainerfactory Jettycontainer = new Jettyembeddedservletcontainerfactory ();
    Jettycontainer.setport (9000);
    Jettycontainer.setcontextpath ("/home");
return jettycontainer; }

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.