Skip to content

Commit 7a793a1

Browse files
Merge branch '2.2.x' into 2.3.x
Fixes gh-21036 in 2.3.1
2 parents fdd908d + 0fa1d0e commit 7a793a1

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerExceptionResolver.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.springframework.beans.factory.ListableBeanFactory;
2727
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
2829
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
2930
import org.springframework.web.servlet.HandlerExceptionResolver;
3031
import org.springframework.web.servlet.ModelAndView;
@@ -51,13 +52,8 @@ public ModelAndView resolveException(HttpServletRequest request, HttpServletResp
5152
if (this.resolvers == null) {
5253
this.resolvers = extractResolvers();
5354
}
54-
ModelAndView resolved = this.resolvers.stream()
55-
.map((resolver) -> resolver.resolveException(request, response, handler, ex)).filter(Objects::nonNull)
56-
.findFirst().orElse(null);
57-
if (resolved != null && resolved.isEmpty()) {
58-
request.setAttribute("javax.servlet.error.exception", ex);
59-
}
60-
return resolved;
55+
return this.resolvers.stream().map((resolver) -> resolver.resolveException(request, response, handler, ex))
56+
.filter(Objects::nonNull).findFirst().orElse(null);
6157
}
6258

6359
private List<HandlerExceptionResolver> extractResolvers() {
@@ -66,6 +62,7 @@ private List<HandlerExceptionResolver> extractResolvers() {
6662
list.remove(this);
6763
AnnotationAwareOrderComparator.sort(list);
6864
if (list.isEmpty()) {
65+
list.add(new DefaultErrorAttributes());
6966
list.add(new DefaultHandlerExceptionResolver());
7067
}
7168
return list;

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/CompositeHandlerExceptionResolverTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ void resolverShouldAddDefaultResolverIfNonePresent() {
6767
ModelAndView resolved = resolver.resolveException(this.request, this.response, null, exception);
6868
assertThat(resolved).isNotNull();
6969
assertThat(resolved.isEmpty()).isTrue();
70-
assertThat(this.request.getAttribute("javax.servlet.error.exception")).isSameAs(exception);
7170
}
7271

7372
private void load(Class<?>... configs) {

0 commit comments

Comments
 (0)