zalando/problem-spring-web如何隐藏stackTrace?

来源:3-6 异常的处理

LayLowMay

2021-02-22

@ControllerAdvice
public class ExceptionHandling implements ProblemHandling {
    @Override
    public boolean isCausalChainsEnabled() {
        // 决定堆栈信息是否写到json当中去,建议[生产环境]关闭
        return false;
    }
}

还是会有堆栈信息

http://img.mukewang.com/szimg/60338beb0966fd4620701210.jpg

写回答

2回答

LayLowMay

提问者

2021-03-03

首先, 需要实现的两个类我选择在一个类里实现

并且不用重写isCausalChainsEnabled方法, 因为感觉没啥影响

//img.mukewang.com/szimg/603f572309d9931d13740428.jpg

在配置类WebMvcConfig里, 配置ObjectMapper, 如果需要堆栈信息就不配置

//img.mukewang.com/szimg/603f577309eb1d7013260650.jpg

0
1
叫我滨哥哥
我配置了,也还打印。。。啥情况。不过我两个两个类分开实现的
2023-07-31
共1条回复

接灰的电子产品

2021-03-01

在 WebMvcConfig 中加入


```java

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
   log.debug("Configuring custom HttpMessageConverters.");
   ObjectMapper mapper = Jackson2ObjectMapperBuilder.json()
           .modules(new ProblemModule(), new ConstraintViolationProblemModule()).build();

   converters.add(new MappingJackson2HttpMessageConverter(mapper));
}

```

0
1
LayLowMay
老师, 这样不行, 但我发现方法了, 我在下面自问自答吧
2021-03-03
共1条回复

Spring Security+OAuth2 精讲,打造企业级认证与授权

一站式掌握主流安全框架与行业解决方案,从容应对各种安全难题。

1042 学习 · 316 问题

查看课程