Only works for those spring beans present in the test class. If you need to inject the mock in every bean that depends on, you must declare and autowire all those beans ( although you do not require them ).
Mocks are injected after all the Spring initializations and post-processing. If you are using @PostConstruct, FactoryBean or similar, your mocks will be injected too late and will not be invoked.
An alternative is to use @MockedBean and @EnableMockedBean. By means of these annotations, mocks are created and directly injected into the Spring Context. The original beans are replaced by the mocks, before any initialization and post-processing happen.