Skip to content
Advertisement

No mapping for request with mockmvc

Currently struggling with problem when I get ‘mapping error for request’ with following controller/test configuration. Controller:

JavaScript

Test:

JavaScript

Configuration:

JavaScript

After test execution I get No mapping for POST /subscriber/session

The reason for the struggle is that my code from other modules with the same configuration works fine. Can somebody point out what am I missing ? Thanks in advance!

Advertisement

Answer

Apparently you are loading a configuration class to mock beans, this interferes with the other parts of Spring Boot and probably leads to partially loading your application. I suspect only the mocked service is available.

Instead of the test configuration use @MockBean to create a mock for the service and register behaviour on it.

JavaScript

If the only thing you want to test is your controller you might also want to consider using @WebMvcTest instead of @SpringBootTest.

JavaScript

This will load a scaled-down version of the context (only the web parts) and will be quicker to run.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement