Skip to content

Commit 4375f44

Browse files
committed
Merge pull request #34503 from vy
* gh-34503: Polish "Allow ProblemDetailsExceptionHandlers to be proxied" Allow ProblemDetailsExceptionHandlers to be proxied Closes gh-34503
2 parents 91c5d41 + 1eb5bbe commit 4375f44

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ProblemDetailsExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
* @author Brian Clozel
2727
*/
2828
@ControllerAdvice
29-
final class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
29+
class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
3030

3131
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ProblemDetailsExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
* @author Brian Clozel
2727
*/
2828
@ControllerAdvice
29-
final class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
29+
class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
3030

3131
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@
3232
import java.util.function.Consumer;
3333

3434
import jakarta.validation.ValidatorFactory;
35+
import org.aspectj.lang.JoinPoint;
36+
import org.aspectj.lang.annotation.AfterReturning;
37+
import org.aspectj.lang.annotation.Aspect;
3538
import org.assertj.core.api.Assertions;
3639
import org.junit.jupiter.api.Test;
3740
import org.junit.jupiter.params.ParameterizedTest;
3841
import org.junit.jupiter.params.provider.ValueSource;
3942

43+
import org.springframework.aop.support.AopUtils;
4044
import org.springframework.boot.autoconfigure.AutoConfigurations;
45+
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
4146
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
4247
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
4348
import org.springframework.boot.autoconfigure.web.ServerProperties;
@@ -645,6 +650,17 @@ void problemDetailsEnabledAddsExceptionHandler() {
645650
.run((context) -> assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class));
646651
}
647652

653+
@Test
654+
void problemDetailsExceptionHandlerDoesNotPreventProxying() {
655+
this.contextRunner.withConfiguration(AutoConfigurations.of(AopAutoConfiguration.class))
656+
.withBean(ExceptionHandlerInterceptor.class)
657+
.withPropertyValues("spring.webflux.problemdetails.enabled:true")
658+
.run((context) -> {
659+
assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class);
660+
assertThat(AopUtils.isCglibProxy(context.getBean(ProblemDetailsExceptionHandler.class)));
661+
});
662+
}
663+
648664
@Test
649665
void problemDetailsBacksOffWhenExceptionHandler() {
650666
this.contextRunner.withPropertyValues("spring.webflux.problemdetails.enabled:true")
@@ -957,4 +973,14 @@ static class CustomExceptionHandler extends ResponseEntityExceptionHandler {
957973

958974
}
959975

976+
@Aspect
977+
static class ExceptionHandlerInterceptor {
978+
979+
@AfterReturning(pointcut = "@annotation(org.springframework.web.bind.annotation.ExceptionHandler)",
980+
returning = "returnValue")
981+
void exceptionHandlerIntercept(JoinPoint joinPoint, Object returnValue) {
982+
}
983+
984+
}
985+
960986
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@
3636
import jakarta.servlet.http.HttpServletRequest;
3737
import jakarta.servlet.http.HttpServletResponse;
3838
import jakarta.validation.ValidatorFactory;
39+
import org.aspectj.lang.JoinPoint;
40+
import org.aspectj.lang.annotation.AfterReturning;
41+
import org.aspectj.lang.annotation.Aspect;
3942
import org.junit.jupiter.api.Test;
4043

44+
import org.springframework.aop.support.AopUtils;
4145
import org.springframework.boot.autoconfigure.AutoConfigurations;
46+
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
4247
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
4348
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
4449
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
@@ -988,6 +993,17 @@ void problemDetailsEnabledAddsExceptionHandler() {
988993
.run((context) -> assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class));
989994
}
990995

996+
@Test
997+
void problemDetailsExceptionHandlerDoesNotPreventProxying() {
998+
this.contextRunner.withConfiguration(AutoConfigurations.of(AopAutoConfiguration.class))
999+
.withBean(ExceptionHandlerInterceptor.class)
1000+
.withPropertyValues("spring.mvc.problemdetails.enabled:true")
1001+
.run((context) -> {
1002+
assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class);
1003+
assertThat(AopUtils.isCglibProxy(context.getBean(ProblemDetailsExceptionHandler.class)));
1004+
});
1005+
}
1006+
9911007
@Test
9921008
void problemDetailsBacksOffWhenExceptionHandler() {
9931009
this.contextRunner.withPropertyValues("spring.mvc.problemdetails.enabled:true")
@@ -1539,4 +1555,14 @@ static class CustomExceptionHandler extends ResponseEntityExceptionHandler {
15391555

15401556
}
15411557

1558+
@Aspect
1559+
static class ExceptionHandlerInterceptor {
1560+
1561+
@AfterReturning(pointcut = "@annotation(org.springframework.web.bind.annotation.ExceptionHandler)",
1562+
returning = "returnValue")
1563+
void exceptionHandlerIntercept(JoinPoint joinPoint, Object returnValue) {
1564+
}
1565+
1566+
}
1567+
15421568
}

0 commit comments

Comments
 (0)