我目前正在尝试将我的应用程序从spring boot 1.5.x迁移到reactive堆栈上的2.x.x。我正面临着一个我不能解决的奇怪的问题。希望有人知道这个问题的解决方案。
我实现了一个api来接收一个用户jwt令牌,作为头上的"Authorization“字段。api是一个POST方法,它在body中接收来自用户的某个json数据,然后转到后端进行处理。不幸的是,当我添加头部时,我一直收到http 404错误,当我在postman中删除它时,正常的200错误。这是我的控制器。
@RestController
@RequestMapping("/user")
@Slf4j
public class UserHandler {
@Autowired
private UserService service;
@Autowired
private Utility utility;
@PostMapping("/updateLink")
public Mono<ServerResponse> addNewAccountLinkAPI(@RequestHeader(name="Authorization") String id, @RequestBody UpdateAccountLink request){
return Mono.just(request)
.flatMap(s -> service.addNewAccountLink(s))
.flatMap(s -> ok().body(BodyInserters.fromObject(new RespWrap("Success", new Date(), null, s))))
.switchIfEmpty(badRequest().body(BodyInserters.fromObject(new RespWrap("Failed", new Date(), "Failed to create new link", null))));
}
}下面是我的简单安全配置
@Configuration
@EnableWebFluxSecurity
@EnableWebFlux
public class ResourceServerConfig implements WebFluxConfigurer {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http, FirebaseAuthenticationManager manager) {
http
.authorizeExchange().anyExchange().permitAll()
.and().csrf().disable();
return http.build();
}
}谁能就这个问题给我指点一下。这看起来确实像是缺少配置的问题。
发布于 2018-12-21 06:05:43
我发现你的代码片段有两个问题。
首先,您不应该添加@EnableWebFlux,因为它会完全禁用Spring Boot所做的自动配置。Spring MVC应用程序中的@EnableWebMvc也是如此。
其次,您混合了WebFlux注释和WebFlux函数。您正在使用的注释很好,但是应该只使用when writing functional handlers的ServerResponse类型。您应该在这里尝试使用ResponseEntity。
https://stackoverflow.com/questions/53854593
复制相似问题