I have a basic SpringBoot app., embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.
I have this class:
@Service
public
The whole point of WebMvcTest is to only load the MVC components. Other components must be mocked. Read the documentation:
To test Spring MVC controllers are working as expected you can use the @WebMvcTest annotation. @WebMvcTest will auto-configure the Spring MVC infrastructure and limit scanned beans to @Controller, @ControllerAdvice, @JsonComponent, Filter, WebMvcConfigurer and HandlerMethodArgumentResolver. Regular @Component beans will not be scanned when using this annotation.
Often @WebMvcTest will be limited to a single controller and used in combination with @MockBean to provide mock implementations for required collaborators.