2017-02-13 82 views
0

我有我的项目SpringBoot 1.5.1 gradle。Spring控制器被调用2次

我需要用“OK”或其他一些状态来回应pdf文件。

所以问题是当我用“邮差”代码调用2次时。 当我请求“卷曲”代码调用1次。

显然我想调用它1次。

我有一个应用程序类:

@SpringBootApplication 
public class Application { 
    public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 
} 
} 

我与控制器:

@RequestMapping(value = "/report/{reportTemplate:.+}", method = POST) 
@ResponseBody 
public ResponseEntity createReport(HttpEntity<List<ParametersEntity>> httpEntity, 
            @PathVariable String reportTemplate) throws IOException { 

byte[] data = ...;// my data 
return ResponseEntity 
       .ok() 
       .contentLength(data.length) 
       .contentType(MediaType.APPLICATION_PDF) 
       .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=output.pdf") 
       .contentType(MediaType.parseMediaType(MediaType.APPLICATION_PDF_VALUE)) 
       .body(data); 

    } 

createReport@RestController类。

我也有application.properties文件在我的src/main /资源/

server.port: 10500 
management.port: 10501 
management.address: 127.0.0.1 
+0

什么是您的邮差版本?这似乎是一个已知的问题。 –

回答

1

你的代码看起来OK。它没有错。

如果你在DEBUG模式调用从POSTMAN它可能会混淆,并发出第二次请求时请求时。我觉得这取决于一些配置。但是,虽然CURL没有问题,但您必须搜索POSTMAN中的问题,可能不是您的代码。

+0

PS:我会把这留作评论,但我没有足够的声望去做。 – Leonardo