Skip to content

@WebMvcTest does not include applicationTaskExecutor #14301

@mdeinum

Description

@mdeinum

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general ideal-for-contribution issues. Thanks!

Problem

When an MVC controller defines an async result (for instance a Mono or Flux from Project Reactor) it has to be processed in a background thread and Spring MVC couldn't have an opinion about the pool settings to use so it creates a SimpleAsyncTaskExecutor that's not suitable for production use. In such setup, the following warning is emitted:

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.

An earlier milestone of Spring Boot 2.1 introduced support for an applicationTaskExecutor bean and a general TaskExecutorAutoConfiguration. When such bean is present, the MVC configuration is automatically configured to use it. So far so good except that if you write a test with such setup and @WebMvcTest the warning is emitted again. The problem is that TaskExecutorAutoConfiguration is not part of the auto-configurations contributed by @WebMvcTest and therefore the applicationTaskExecutor bean is not created.

Solution

We should write a test that uses @WebMvcTest and verifies the MVC configuration has been updated properly. There is an existing test that could be used for inspiration. Another solution would be to update the ExampleController so that a method returns a Mono<String> rather than String and check with an OutputCapture that the warning is not emitted.

Either way, once the test fails, we can fix the code by adding TaskExecutorAutoConfiguration to @WebMvcTest. MVC is auto-configured via @AutoConfigureWebMvc and the list of auto-configurations are in META-INF/spring.factories under the org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc key. When you add the extra entry, pay attention that they ordered alphabetically.

Steps to Fix

  • Claim this issue with a comment here, below, and ask any clarifying questions you need
  • Set up a repository locally following the Contributing Guidelines
  • Try to fix the issue following the steps above
  • Commit your changes and start a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: first-timers-onlyAn issue that can only be worked on by brand new contributorsstatus: supersededAn issue that has been superseded by anothertype: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions