How to configure Jetty in spring-boot (easily?)

37,024

Solution 1

There are some general extension points for servlet containers and also options for plugging Jetty API calls into those, so I assume everything you would want is in reach. General advice can be found in the docs. Jetty hasn't received as much attention yet so there may not be the same options available for declarative configuration as with Tomcat, and for sure it won't have been used much yet. If you would like to help change that, then help is welcome.

Solution 2

Possibility to configure Jetty (in parts) programatically from http://howtodoinjava.com/spring/spring-boot/configure-jetty-server/

@Bean
public JettyEmbeddedServletContainerFactory  jettyEmbeddedServletContainerFactory() {
    JettyEmbeddedServletContainerFactory jettyContainer = 
        new JettyEmbeddedServletContainerFactory();

    jettyContainer.setPort(9000);
    jettyContainer.setContextPath("/home");
    return jettyContainer;
}
Share:
37,024
Elvin
Author by

Elvin

Updated on June 12, 2021

Comments

  • Elvin
    Elvin about 3 years

    By following the tutorial, I could bring up the spring-boot with Jetty running using the following dependencies.

        <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-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
    

    However, how could I configure the Jetty server such as:

    1. Server threads (Queue thread pool)
    2. Server connectors
    3. Https configurations.
    4. all those configuration available in Jetty...?

    Is there an easy way to do in

    1. application.yml?
    2. Configuration class?

    Any example would be greatly appreciated.

    Many thanks!!

  • Elvin
    Elvin over 10 years
    Thanks very much for your explanation!
  • JaskeyLam
    JaskeyLam almost 8 years
    “Unable to start embedded container” after add that pom, would you please help to check stackoverflow.com/questions/39557018/…
  • Dave Syer
    Dave Syer almost 8 years
    Works for me. Check the samples in spring boot.