0

从 Spring 5.0.0 M1 升级到 M2 后,此代码已停止工作(我从更改SseEventServerSentEvent类):

@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] 
4

1 回答 1

1

https://jira.spring.io/browse/SPR-14748中解决

返回Flux<ServerSentEvent<String>>将意味着text/event-stream序列化。

于 2016-09-28T15:36:26.303 回答