Spring boot jetty example

Common servlet container settings can be configured using Spring Environment properties. Usually you would define the properties in your application.properties file.

Spring boot jetty as embedded server

Step 1: exclude tomcat from spring boot web starter

<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 2: Now add Jetty dependency – spring-boot-starter-jetty maven

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

Thats All…

How to run

mvn spring-boot:run

 

Download

Jetty as embedded server maven

 

Alternatively you can try Programmatic customization for jetty configuration

If you need to configure your embedded servlet container programmatically you can register a Spring bean that implements the EmbeddedServletContainerCustomizer interface. EmbeddedServletContainerCustomizer provides access to the ConfigurableEmbeddedServletContainer which includes numerous customization setter methods.

import org.springframework.boot.context.embedded.*;
        import org.springframework.stereotype.Component;

@Component
public class CustomizationBean implements EmbeddedServletContainerCustomizer {

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        container.setPort(9000);
    }

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *