Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!!

like image 371
Elvin Avatar asked Dec 08 '13 14:12

Elvin


People also ask

How do you put Jetty in spring boot?

To use Jetty in your Spring Boot application, we can use the spring-boot-starter-jetty starter. Spring Boot provides Tomcat and Jetty dependencies bundled together as separate starters to help make this process as easy as possible. Add the spring-boot-starter-jetty starter in your pom. xml file.

What version of Jetty does spring boot use?

Jetty 9.2 works with Spring Boot, but the default is to use Jetty 9.3.

Does spring boot use Tomcat or Jetty?

The Spring Boot starters ( spring-boot-starter-web in particular) use Tomcat as an embedded container by default. You need to exclude those dependencies and include the Jetty one instead.


2 Answers

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; } 
like image 28
Markus Schulte Avatar answered Sep 23 '22 02:09

Markus Schulte


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.

like image 167
Dave Syer Avatar answered Sep 25 '22 02:09

Dave Syer