spring-boot
jersey
REST API
endpoints
tutorial

Listing all deployed rest endpoints spring-boot, jersey

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Knowing all deployed REST endpoints in your application is essential for debugging, documentation, and API discovery. Spring Boot provides RequestMappingHandlerMapping to introspect all mapped routes, and the Actuator /mappings endpoint exposes this without writing code. For Jersey (JAX-RS), you can query the ResourceConfig or Application model at runtime to list all resource methods. Both frameworks also support custom startup listeners that log every registered endpoint when the application starts.

Spring Boot: RequestMappingHandlerMapping

java
1import org.springframework.beans.factory.annotation.Autowired;
2import org.springframework.boot.CommandLineRunner;
3import org.springframework.stereotype.Component;
4import org.springframework.web.method.HandlerMethod;
5import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
6import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
7
8import java.util.Map;
9
10@Component
11public class EndpointLister implements CommandLineRunner {
12
13    @Autowired
14    private RequestMappingHandlerMapping handlerMapping;
15
16    @Override
17    public void run(String... args) {
18        Map<RequestMappingInfo, HandlerMethod> methods = handlerMapping.getHandlerMethods();
19        methods.forEach((info, method) -> {
20            System.out.printf("%-8s %-40s -> %s.%s%n",
21                info.getMethodsCondition(),
22                info.getPatternsCondition(),
23                method.getBeanType().getSimpleName(),
24                method.getMethod().getName());
25        });
26    }
27}

This prints every mapped URL pattern, the HTTP methods it accepts, and the controller method that handles it.

Spring Boot Actuator /mappings Endpoint

properties
# application.properties
management.endpoints.web.exposure.include=mappings,info,health
bash
# Query all endpoint mappings
curl http://localhost:8080/actuator/mappings | jq '.contexts.application.mappings.dispatcherServlets'

The Actuator mappings endpoint returns a JSON document with every handler mapping, including Spring MVC controllers, resource handlers, and error mappings. No custom code required — just add spring-boot-starter-actuator as a dependency.

Spring Boot: ApplicationEventListener

java
1import org.springframework.context.event.ContextRefreshedEvent;
2import org.springframework.context.event.EventListener;
3import org.springframework.stereotype.Component;
4import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
5
6@Component
7public class EndpointLogger {
8
9    private final RequestMappingHandlerMapping mapping;
10
11    public EndpointLogger(RequestMappingHandlerMapping mapping) {
12        this.mapping = mapping;
13    }
14
15    @EventListener
16    public void onApplicationEvent(ContextRefreshedEvent event) {
17        mapping.getHandlerMethods().forEach((info, method) -> {
18            System.out.println(info.getPatternsCondition() + " " + info.getMethodsCondition());
19        });
20    }
21}

Jersey (JAX-RS): Listing Resource Endpoints

java
1import org.glassfish.jersey.server.ResourceConfig;
2import org.glassfish.jersey.server.model.Resource;
3import org.glassfish.jersey.server.model.ResourceMethod;
4
5import javax.annotation.PostConstruct;
6import javax.inject.Inject;
7
8public class JerseyEndpointLister {
9
10    @Inject
11    private ResourceConfig resourceConfig;
12
13    @PostConstruct
14    public void listEndpoints() {
15        for (Resource resource : resourceConfig.getResources()) {
16            printResource("", resource);
17        }
18    }
19
20    private void printResource(String basePath, Resource resource) {
21        String path = basePath + resource.getPath();
22        for (ResourceMethod method : resource.getResourceMethods()) {
23            System.out.printf("%-8s %s%n", method.getHttpMethod(), path);
24        }
25        for (Resource child : resource.getChildResources()) {
26            printResource(path, child);
27        }
28    }
29}

Jersey with Spring Boot Integration

java
1import org.glassfish.jersey.server.ResourceConfig;
2import org.glassfish.jersey.server.model.Resource;
3import org.springframework.stereotype.Component;
4
5import javax.ws.rs.Path;
6import java.util.Set;
7
8@Component
9public class JerseyConfig extends ResourceConfig {
10
11    public JerseyConfig() {
12        packages("com.example.api");
13        register(MyResource.class);
14
15        // Log endpoints after registration
16        Set<Class<?>> classes = getClasses();
17        classes.stream()
18            .filter(c -> c.isAnnotationPresent(Path.class))
19            .forEach(c -> {
20                Path path = c.getAnnotation(Path.class);
21                System.out.println("Registered resource: " + path.value() + " -> " + c.getName());
22            });
23    }
24}

REST Endpoint Documentation with Swagger/OpenAPI

xml
1<!-- pom.xml -->
2<dependency>
3    <groupId>org.springdoc</groupId>
4    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
5    <version>2.3.0</version>
6</dependency>
bash
1# OpenAPI JSON spec with all endpoints
2curl http://localhost:8080/v3/api-docs
3
4# Interactive Swagger UI
5open http://localhost:8080/swagger-ui.html

Springdoc-openapi auto-scans all Spring MVC and Jersey endpoints and generates a live OpenAPI specification. This is the most comprehensive approach for both discovery and documentation.

Common Pitfalls

  • Forgetting to expose the Actuator mappings endpoint: By default, Spring Boot Actuator only exposes health. You must add management.endpoints.web.exposure.include=mappings to see endpoint mappings. Without this, GET /actuator/mappings returns 404.
  • Missing child resources in Jersey listing: Jersey resources can have sub-resource locators that return other resource classes. Iterating only top-level getResources() misses nested endpoints. Recursively traverse getChildResources() to capture the full tree.
  • Confusing Spring MVC and Jersey mappings in the same app: When both Spring MVC and Jersey are configured in the same application, they serve different URL prefixes. Spring MVC endpoints appear in RequestMappingHandlerMapping, while Jersey endpoints appear in the Jersey ResourceConfig. Query both to get a complete list.
  • Not accounting for path prefixes: Jersey typically runs under a servlet path like /api/*. The resource @Path annotations are relative to this prefix. When listing endpoints, prepend the servlet mapping path to get the actual URL.
  • Actuator endpoint security blocking access: Spring Security often protects Actuator endpoints. In production, /actuator/mappings may return 401/403. Configure security rules to allow access for admin users or restrict it to internal networks only.

Summary

  • Use RequestMappingHandlerMapping.getHandlerMethods() to list all Spring MVC endpoints programmatically
  • Enable Spring Boot Actuator with mappings exposure for zero-code endpoint discovery via HTTP
  • For Jersey, iterate ResourceConfig.getResources() recursively to capture all JAX-RS endpoints
  • Use springdoc-openapi for auto-generated, interactive API documentation with Swagger UI
  • When both frameworks coexist, query both mapping systems to get a complete endpoint inventory

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.