From b674906e3a62378a78c1321b09340ac322514c3e Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 9 May 2023 10:59:05 +0200 Subject: [PATCH] Document @ResponseStatus behavior This commit documents that the ResponseStatus annotation does not override the status set through other means. Closes gh-30305 See gh-18019 --- .../ROOT/pages/web/webmvc/mvc-servlet/viewresolver.adoc | 3 --- .../springframework/web/bind/annotation/ResponseStatus.java | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/viewresolver.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/viewresolver.adoc index 96d9ceb063e1..b6728feb674f 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/viewresolver.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-servlet/viewresolver.adoc @@ -86,9 +86,6 @@ name (such as `redirect:/myapp/some/resource`) redirects relative to the current Servlet context, while a name such as `redirect:https://myhost.com/some/arbitrary/path` redirects to an absolute URL. -Note that, if a controller method is annotated with the `@ResponseStatus`, the annotation -value takes precedence over the response status set by `RedirectView`. - [[mvc-redirecting-forward-prefix]] == Forwarding diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ResponseStatus.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ResponseStatus.java index f69fef63fc73..129605eec4a4 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ResponseStatus.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ResponseStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ * {@link #reason} that should be returned. * *

The status code is applied to the HTTP response when the handler - * method is invoked and overrides status information set by other means, - * like {@code ResponseEntity} or {@code "redirect:"}. + * method is invoked, but does not override status information set by other + * means, such as {@code ResponseEntity} or {@code "redirect:"}. * *

Warning: when using this annotation on an exception * class, or when setting the {@code reason} attribute of this annotation,