Java 使用Spring 5下载PDF文件时出错

Java 使用Spring 5下载PDF文件时出错,java,spring,reactive-programming,project-reactor,Java,Spring,Reactive Programming,Project Reactor,我尝试使用Spring5下载一个PDF文件。下面是我的代码: @RequestMapping(path = "/pdf", method = { RequestMethod.POST }, produces = MediaType.APPLICATION_PDF_VALUE) public Mono<ResponseEntity<Resource>> getPDF(ServerHttpRequest httpRequest) { File file = new

我尝试使用Spring5下载一个PDF文件。下面是我的代码:

@RequestMapping(path = "/pdf", method = { RequestMethod.POST }, produces = MediaType.APPLICATION_PDF_VALUE)
public Mono<ResponseEntity<Resource>> getPDF(ServerHttpRequest httpRequest) 
{
    File file = new File(filepath);
    ResponseEntity<Resource> resource = getResource(file);
    return Mono.justOrEmpty(resource);
}

public ResponseEntity<Resource> getResource(File file) {
   final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
   HttpHeaders headers = new HttpHeaders();
   headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + file.getName());
   headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
   headers.add("Pragma", "no-cache");
   headers.add("Expires", "0");
   return ResponseEntity.ok().headers(headers).contentType(MediaType.APPLICATION_PDF).contentLength(file.length()).body(new InputStreamResource(inputStream));
}
但我得到了以下例外:

java.lang.NoSuchMethodError: reactor.core.publisher.Flux.doOnDiscardLjava/lang/Class;Ljava/util/function/Consumer;Lreactor/core/publisher/Flux

在 org.springframework.core.io.buffer.DataBufferUtils.readByteChannelDataBufferUtils.java:105 在 org.springframework.core.io.buffer.DataBufferUtils.readDataBufferUtils.java:202 在 org.springframework.core.io.buffer.DataBufferUtils.readDataBufferUtils.java:170 在 org.springframework.core.codec.ResourceEncoder.encodeResourceEncoder.java:76 在 org.springframework.core.codec.ResourceEncoder.encodeResourceEncoder.java:40 在


您的依赖项有错误。您使用的是Spring Framework和Project Reactor的不兼容版本:

java.lang.NoSuchMethodError:reactor.core.publisher.Flux.doOnDiscardLjava/lang/Class;Ljava/util/function/Consumer;Lreactor/core/publisher/Flux


更正项目设置,您可以使用查看正确设置的外观。

您的依赖项有错误。您使用的是Spring Framework和Project Reactor的不兼容版本:

java.lang.NoSuchMethodError:reactor.core.publisher.Flux.doOnDiscardLjava/lang/Class;Ljava/util/function/Consumer;Lreactor/core/publisher/Flux

更正项目设置后,可以使用查看正确设置的外观