小编dk7*_*dk7的帖子

在Spring Boot上使用StreamingResponseBody下载大文件的异步超时

我正在尝试公开一个REST服务,它可以下载大型文件流,而不需要先保存在内存中.另外我需要这个来支持异步调用,如果(至少)两个用户在同一时间调用这个URL应该能够同时下载它.应用程序使用Spring Boot设置.
这就是我在Controller上的内容:

@RestController
public class MyController {

   private MyService service;

   @Autowired
   public MyController(MyService service) {
       this.service = service;
   }

   @RequestMapping(
        value = "download",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
   public ResponseEntity<StreamingResponseBody> downloadAsync() throws IOException {

       StreamingResponseBody responseBody = outputStream -> {
           service.download(outputStream);
           outputStream.close();
       };

       return ResponseEntity.ok(responseBody);
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是我在服务上的内容(下载URL只是测试此行为的示例):

@Service
public class MyService {

    private RestTemplate restTemplate;

    @Autowired
    public MyService(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public void download(OutputStream outputStream) {

        ResponseExtractor<Void> responseExtractor = clientHttpResponse -> {
            InputStream inputStream …
Run Code Online (Sandbox Code Playgroud)

asynchronous spring-mvc spring-boot

6
推荐指数
2
解决办法
7026
查看次数

setenv.sh在Tomcat中到底有什么用?

我搜索了很多,但找不到任何关于此的有用信息:

setenv.sh在 Tomcat 中 到底有什么用?

假设我们有一个 REST API(使用 Java EE 或 Spring 构建),它使用一些参数/变量,例如 AWS 凭证、数据库凭证等。

如果我们使用多个实例并使用不同的参数/变量,那么使用环境变量对应用程序进行参数化是否有意义?

或者setenv.sh不适合这样的事情?

提前致谢

spring tomcat credentials

5
推荐指数
1
解决办法
6999
查看次数