Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix - Executor is required to handle java.util.concurrent.Callable return values

I have a controller in Spring Boot/Spring Data Rest where my handler downloads a file like this

@RequestMapping(method = GET, value = "/orderAttachments/{id}/download")
    @ResponseStatus(HttpStatus.OK)
    public ResponseEntity<StreamingResponseBody> downloadAttachment(@PathVariable("id") Long attachmentID, HttpServletRequest request)
            throws IOException {

        InputStream inputStream = fileManager.getInputStream(orderAttachment);

        StreamingResponseBody responseBody = outputStream -> {

            int numberOfBytesToWrite;
            byte[] data = new byte[1024];
            while ((numberOfBytesToWrite = inputStream.read(data, 0, data.length)) != -1) {
                outputStream.write(data, 0, numberOfBytesToWrite);
            }

            inputStream.close();
        };

        return ResponseEntity
                .ok()
                .contentLength(orderAttachment.getFileSize())
                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""  + orderAttachment.getFileName()+ "\"")
                .contentType(MediaType.APPLICATION_OCTET_STREAM)
                .body(responseBody);
    }

I got this error in the console

!!!
An Executor is required to handle java.util.concurrent.Callable return values.
Please, configure a TaskExecutor in the MVC config under "async support".
The SimpleAsyncTaskExecutor currently in use is not suitable under load.
-------------------------------
Request URI: '/api/v1/orderAttachments/163/download'
!!!

But everything works, I can download the file from calling the API

like image 667
erotsppa Avatar asked Jan 04 '20 19:01

erotsppa


1 Answers

Spring boot in 2.1.0 provides auto configuration for task executors and uses for @EnableAsync and Spring MVC Async support.

There is no task executor bean / webMvcConfigurer configuration is needed from application. If you have one please remove it and you should be good.

If you like to control the values you can adjust using applicaion properties/yml file with spring.task.execution.*. Full listing can be found here

More details here and here

like image 135
s7vr Avatar answered Sep 19 '22 16:09

s7vr