With Spring Boot 2.1 bean overriding is disabled by default, which is a good thing.
However I do have some tests where I replace beans with mocked instances using Mo
It is allowed to override @Component with @Bean by default. In your case
@Service
public class AService {
}
@Component
public class BService {
@Autowired
public BService() { ... }
}
@Configuration
@ComponentScan
public BaseConfiguration {
}
@Configuration
// WARNING! Doesn't work with @SpringBootTest annotation
@Import({BaseConfiguration.class})
public class TestConfiguration {
@Bean // you allowed to override @Component with @Bean.
public BService bService() {
return Mockito.mock(BService.class);
}
}