覆盖配置为春天
这是我的情况。我有一个父级项目,它具有bean配置,如下所示,
@Configuration
public class Configuration {
@Bean
public BeanA beanA(@Autowired BeanB beanB) {
return new BeanA(beanB);
}
我想覆盖此配置,因为我需要覆盖BeanB上的某些定义。
@Configuration
public class Configuration {
@Bean
public BeanA beanA(@Autowired BeanC beanC) {
return new BeanA(beanC);
}
我的C型豆类在哪里
public class BeanC extends BeanB { ... }
,但是当我运行应用程序时,我总是得到来自父母的配置。还启用了bean-depinition-coverriding
spring.main.allow-bean-definition-overriding=true
,任何人都知道如何告诉弹簧容器使用我的bean定义,而不是来自我父母项目的定义。 提前致谢!
Here is my situation. I have a parent project which has a bean configuration as follows
@Configuration
public class Configuration {
@Bean
public BeanA beanA(@Autowired BeanB beanB) {
return new BeanA(beanB);
}
I want to override this configuration, because I need to override some of the definitions on BeanB.
@Configuration
public class Configuration {
@Bean
public BeanA beanA(@Autowired BeanC beanC) {
return new BeanA(beanC);
}
Where my bean of type C
public class BeanC extends BeanB { ... }
But when I run the application, I am always getting the configuration coming from the parent. Also have enabled the bean-definition-overriding
spring.main.allow-bean-definition-overriding=true
Does anyone knows how can I tell the spring container to use my bean definition instead the one that is coming from my parent project.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以用@primary注释来注释豆(请参阅: https://wwwww.baeldung-com/spring-.com/spring-.com/spring-.com/spring-.com/主要)
You can annotate your bean with @Primary annotation (see: https://www.baeldung.com/spring-primary)