简体   繁体   English

如果找不到实现bean,则自动装配默认实现

[英]Autowire a default implementation if implemenation bean is not found

I have an interface with 2 default methods. 我有一个界面有2个默认方法。 If the implementation is not found, I wish autowire a proxy bean with these 2 default methods. 如果找不到实现,我希望使用这两种默认方法自动装配代理bean。 Is this possible in spring? 这可能在春天吗?

You need to define bean in some configuration 您需要在某些配置中定义bean

@Bean
@ConditionalOnMissingBean
public Foo foo(){
    return new Foo() {};
}

where Foo is your interface. Foo是你的界面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ApplicationContext中找到Bean,但在尝试自动装配时找不到 - Bean found in ApplicationContext, but not found when attempting to Autowire Spring 自动装配唯一的实现而不定义 bean - Spring autowire the only implementation without defining the bean 如果byName失败,则将默认bean设置为自动装配 - Set a default bean to autowire if byName fails 将Spring Bean自动连接到默认方法的接口 - Autowire Spring Bean into interface for default method 没有默认构造函数的Autowire Bean,使用config批注 - Autowire Bean with no default constructor, using config annotation 春季:未找到符合自动装配条件的匹配豆 - Spring: No matching bean found which qualifies as autowire Spring Autowire Bean具有多个接口实现,在方法中定义实现 - Spring Autowire Bean with multiple Interface Implementations, define Implementation in method 如何基于注释为@Autowire字段提供不同的bean实现? - How provide a different bean implementation to @Autowire field based on annotation? 在spring项目中,hibernate autowire没有遇到麻烦,找不到bean错误 - Little trouble with hibernate autowire in a spring project, bean not found error 如何自动连接@service类? 找不到依赖类型的合格Bean - How to autowire @service class ? No qualifying bean of type found for dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM