Skip to main content

Microservice Jetty Overview

The Jetty Microservice API consists of a combination of the Juneau Core, Server, and Client APIs and an embedded Eclipse Jetty Servlet Container.

The API builds upon the juneau-microservice classes to produce easy-to-create and easy-to-use microservices in a standard Java 17+ environment.

Renamed in 10.0 — juneau-microservice-core is now published as juneau-microservice. The Jetty module is no longer a subclass of Microservice; it contributes a single @Configuration class (JettyConfiguration) that the user adds to Microservice.Builder.configurations(...).

The juneau-microservice-jetty library consists of the following classes:

org.apache.juneau.microservice.jetty - PackageJettyMicroservice - Zero-config static-call facade that boots a Jetty microservice in a single line.JettyConfiguration - @Configuration class that wires Jetty into a Microservice.JettyServerComponent - Lifecycle-participating bean that owns the Jetty server.JettySettings - Immutable value bean holding programmatic Jetty knobs (ports, jetty.xml, var resolution).JettyServerFactory - Interface for defining custom Jetty server factories.BasicJettyServerFactory - Default factory that builds the server from jetty.xml.HealthProbeConfiguration - Opt-in @Configuration that auto-mounts the health/readiness/liveness probe servlet.

The most-basic creation of a Jetty microservice from an entry-point method is shown below:

public class App {
public static void main(String[] args) throws Exception {
Microservice
.create()
.args(args)
.configurations(JettyConfiguration.class, AppConfig.class)
.build()
.start()
.startConsole()
.join();
}

@Configuration
public static class AppConfig {
@Bean
Servlet rootResources() { return new RootResources(); }
}
}

RootResources (or any @Bean Servlet whose class is annotated with @Rest) is auto-mounted at the path declared in @Rest(path = "...").

See also​