diff --git a/problem-spring-web-autoconfigure/src/main/java/org/zalando/problem/spring/web/autoconfigure/ProblemJacksonAutoConfiguration.java b/problem-spring-web-autoconfigure/src/main/java/org/zalando/problem/spring/web/autoconfigure/ProblemJacksonAutoConfiguration.java index 598338a9..578f2d2b 100644 --- a/problem-spring-web-autoconfigure/src/main/java/org/zalando/problem/spring/web/autoconfigure/ProblemJacksonAutoConfiguration.java +++ b/problem-spring-web-autoconfigure/src/main/java/org/zalando/problem/spring/web/autoconfigure/ProblemJacksonAutoConfiguration.java @@ -1,8 +1,10 @@ package org.zalando.problem.spring.web.autoconfigure; import org.apiguardian.api.API; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,6 +12,7 @@ import org.zalando.problem.violations.ConstraintViolationProblemModule; import static org.apiguardian.api.API.Status.INTERNAL; +import static org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute.ALWAYS; /** * Registers Problem Jackson modules when {@link WebMvcAutoConfiguration} is @@ -22,11 +25,14 @@ public class ProblemJacksonAutoConfiguration { @Bean - public ProblemModule problemModule() { - return new ProblemModule(); + @ConditionalOnMissingBean(ProblemModule.class) + public ProblemModule problemModule(ObjectProvider serverProperties) { + ServerProperties props = serverProperties.getIfAvailable(); + return new ProblemModule().withStackTraces(props != null && props.getError().getIncludeStacktrace().equals(ALWAYS)); } @Bean + @ConditionalOnMissingBean(ConstraintViolationProblemModule.class) public ConstraintViolationProblemModule constraintViolationProblemModule() { return new ConstraintViolationProblemModule(); }