加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

JavaConfig中的Spring Bean别名

发布时间:2020-12-15 01:23:59 所属栏目:大数据 来源:网络整理
导读:我有一个@Service注释类,它提供了我可以在我所有项目中使用的核心功能: @Servicepublic class MyService {} 和另一个扩展它以实现项目特定的东西: @Servicepublic class ExtendedMyService extends MyService {} 现在我想配置一个bean别名,以便在使用属性

我有一个@Service注释类,它提供了我可以在我所有项目中使用的核心功能:

@Service
public class MyService {}

和另一个扩展它以实现项目特定的东西:

@Service
public class ExtendedMyService extends MyService {}

现在我想配置一个bean别名,以便在使用属性自动装配它时能够使用@Qualifier(“MyServiceAlias”):

# MyService qualifier (default: myService)
myService.qualifier=extendedMyService

在XML中它看起来像:

它也讨论了here,但我只需要使用XML,JavaConfig.
是否可能以及如何实现?

最佳答案
这是一个开放的Jira:https://jira.spring.io/browse/SPR-6736

解决方法是在@Configuration类中使用@Bean:

@Configuration
public class AppConfig {

  @Bean(name = { "dataSource","subsystemA-dataSource","subsystemB-dataSource" })
  public MyService myService() {}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读