请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

我的配置如下,但是返回的json中没有验证错误的详细信息,请问什么原因?

我的配置如下,但是返回的json中么有验证的详细信息,请问什么原因?

rest client:

###
# @name register
POST {{host}}/authorize/register HTTP/1.1
Content-Type: application/json

{
    "name": "aa"
}

返回的JSON:

HTTP/1.1 400
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json
Transfer-Encoding: chunked
Date: Thu, 09 Sep 2021 06:00:45 GMT
Connection: close

{
“timestamp”: “2021-09-09T06:00:45.649+00:00”,
“status”: 400,
“error”: “Bad Request”,
“path”: “/authorize/register”
}

SecurityConfig.java

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests(req -> req
                        .antMatchers("/authorize/**").permitAll()
                        .antMatchers("/admin/**").hasRole("ADMIN")
                        .antMatchers("/api/**").hasRole("USER")
                        .anyRequest().authenticated())
                .addFilterAt(restAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)
                .csrf(csrf -> csrf.disable());

API:

@RestController
@RequestMapping("/authorize")
public class AuthorizeController {
    @PostMapping("register")
    public UserDto register(@Valid @RequestBody UserDto userDto) {
        return userDto;
    }
}

正在回答 回答被采纳积分+3

1回答

提问者 慕UI2559437 2021-09-09 16:27:59
server:
  error:
    include-binding-errors: always

追加后,OK了。
参考URL,但是我也没有详细确认哈。

https://reflectoring.io/spring-boot-exception-handling/

1 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号