Real World Example

A Platform Starter at Scale

Companies like Swiggy, Flipkart and Netflix run hundreds of Spring services. Platform teams ship an internal starter so that every service gets the same logging format, tracing headers, health checks and error responses on day one. Product teams only add the dependency.

@AutoConfiguration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class PlatformWebAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    FilterRegistrationBean<RequestIdFilter> requestIdFilter() {
        var reg = new FilterRegistrationBean<>(new RequestIdFilter());   // adds X-Request-Id to every request/log line
        reg.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return reg;
    }

    @Bean
    @ConditionalOnMissingBean
    PlatformExceptionHandler platformExceptionHandler() {   // a @RestControllerAdvice returning ProblemDetail
        return new PlatformExceptionHandler();
    }
}

Example

Every ShopEase service now returns the same error shape:

curl -i localhost:8080/api/orders/999

Example output

HTTP/1.1 404 Not Found
X-Request-Id: 7f3c9a12
Content-Type: application/problem+json

{"type":"about:blank","title":"Not Found","status":404,"detail":"Order 999 not found","instance":"/api/orders/999","requestId":"7f3c9a12"}