diff --git a/framework-docs/modules/ROOT/pages/web/webflux/ann-rest-exceptions.adoc b/framework-docs/modules/ROOT/pages/web/webflux/ann-rest-exceptions.adoc index 5a66f3ddf50..8b1e8adc958 100644 --- a/framework-docs/modules/ROOT/pages/web/webflux/ann-rest-exceptions.adoc +++ b/framework-docs/modules/ROOT/pages/web/webflux/ann-rest-exceptions.adoc @@ -135,6 +135,10 @@ Message codes and arguments for each error are also resolved via `MessageSource` | `+{0}+` the list of global errors, `+{1}+` the list of field errors. Message codes and arguments for each error are also resolved via `MessageSource`. +| `NoResourceFoundException` +| (default) +| `+{0}+` the request path (or portion of) used to find a resource + |=== NOTE: Unlike other exceptions, the message arguments for diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-ann-rest-exceptions.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-ann-rest-exceptions.adoc index ed4ad5506c6..1940ebaa780 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-ann-rest-exceptions.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-ann-rest-exceptions.adoc @@ -171,7 +171,7 @@ Message codes and arguments for each error are also resolved via `MessageSource` | `NoResourceFoundException` | (default) -| `+{0}+` the resource +| `+{0}+` the request path (or portion of) used to find a resource | `TypeMismatchException` | (default) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/NoResourceFoundException.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/NoResourceFoundException.java index 4f4ab4cc82e..c32b5ea25e2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/NoResourceFoundException.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/NoResourceFoundException.java @@ -31,9 +31,11 @@ import org.springframework.web.server.ResponseStatusException; @SuppressWarnings("serial") public class NoResourceFoundException extends ResponseStatusException { - public NoResourceFoundException(URI uri, String resourcePath) { - super(HttpStatus.NOT_FOUND, "No static resource " + resourcePath + " for request '" + uri + "'."); + super(HttpStatus.NOT_FOUND, + "No static resource " + resourcePath + " for request '" + uri + "'.", + null, null, new Object[] { resourcePath}); + setDetail("No static resource " + resourcePath + "."); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/NoResourceFoundExceptionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/NoResourceFoundExceptionTests.java index 38ef9800689..9fb2b33bae0 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/NoResourceFoundExceptionTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/NoResourceFoundExceptionTests.java @@ -40,4 +40,9 @@ class NoResourceFoundExceptionTests { assertThat(noResourceFoundException.getBody().getDetail()).isEqualTo("No static resource /resource."); } + @Test + void messageArgumentsShouldContainResourcePath() { + var noResourceFoundException = new NoResourceFoundException(URI.create("/context/resource"), "/resource"); + assertThat(noResourceFoundException.getDetailMessageArguments()).containsExactly("/resource"); + } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/NoResourceFoundException.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/NoResourceFoundException.java index 12c00161e20..b8fb0f1a5fb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/NoResourceFoundException.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/NoResourceFoundException.java @@ -80,6 +80,6 @@ public class NoResourceFoundException extends ServletException implements ErrorR @Override public Object[] getDetailMessageArguments() { - return new String[]{this.resourcePath}; + return new String[] { this.resourcePath }; } }