Advertise with us

Search Mastertheboss

Our eBooks

Using Servlet Context in Quarkus

Quarkus includes the undertow extension, therefore it's fully capable of delivering Servlet applications. In this example, we will show how to use the ServletContext in a REST Application. One challenge is that you cannot @Inject the ServletContext directly as you would do it in a Jave EE environment.

Nevertheless you can count on the JAX-RS annotation to do that:

public class GreetingResource {

    ServletContext servletContext;


 Or, as an alternative you can also do that:

public class HelloResource {

    @Produces({ MediaType.TEXT_PLAIN })
    public Response hello(@Context ServletContext servletContext) {


© 2021 All Rights Reserved.

Please publish modules in offcanvas position.