当使用 Postman 或从 Angular 前端发出请求时,我总是得到空白/空响应 200 OK
即使在错误的路线上也来自后端。
安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/public/**").permitAll()
.anyRequest().authenticated()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
例如,检查用户名是否被占用:
@GetMapping("/available")
public Boolean isUsernameTaken(@RequestParam String username) {
return userService.isUsernameTaken(username);
}
甚至没有进入这个方法,但返回的代码是 200
.
在错误的端点上发出请求 http://localhost:8080/fakeEndpoint/xxxxx
还返回空白页和代码 200。
最佳答案
问题出在扩展 OncePerRequestFilter
的自定义过滤器类中。执行了覆盖 doFilterInternal()
方法,但没有链接过滤 - 我没有在此方法末尾调用 filterChain.doFilter(httpServletRequest, httpServletResponse)
。
关于java - Spring Boot REST API 接受所有请求并返回空白响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60025207/