Is there any way to override a bean discovered by component scan?
问题 I have a java configuration class providing fooBean directly and barBean by component scan. @Configuration @ComponentScan(basePackages = { "com.blah" }) public class Config { @Bean public FooBean fooBean { return new FooBean(); } } and i want to reuse it in the test cases and i need to replace the beans with mocks: @Configuration @Import(Config.class) public class TestConfig { @Bean public FooBean fooBean { return new FooBeanMock(); } @Bean public BarBean barBean { return new BarBeanMock(); }