从 Spring 5.0.0 M1 升级到 M2 后,此代码已停止工作(我从更改SseEvent
为ServerSentEvent
类):
@RestController
public class StringsRestController {
@GetMapping("/strings/sse/event")
public Flux<ServerSentEvent<String>> sse() {
return Flux.interval(Duration.ofMillis(100)).map(l -> {
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
return event;
}).take(2);
}
例外是:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.http.codec.ServerSentEvent and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275) ~[jackson-databind-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110) ~[jackson-databind-2.8.3.jar:2.8.3]