覆盖 Java 配置中的 Bean 定义
我有一个配置类
@Configuration
public class FooConfig{
@Bean
public FooService fooService() { ... }
@Bean
public AbcService abcService() { ... }
}
该类是在我无法更改的库中定义的。我有一个项目,在很多地方都使用。在我的项目中,我有另一个配置类FooService
@Configuration
@Import({
FooConfig.class,
})
public class BarConfig{
@Autowired AbcService abc;
...
}
AbcService
在此处使用,因为有些服务依赖于该服务,并且这些服务在 中声明。但是,此处不使用(仅在控制器中使用)BarConfig
FooService
我需要更改 的实现。我可以在 中定义新豆吗?它是否会覆盖通过 导入的已经存在的定义?FooService
FooService
BarConfig
FooConfig