【发布时间】:2012-05-25 11:34:36
【问题描述】:
我的目标是一个框架,其中可以通过属性文件轻松更改具体类型的 bean。我也更喜欢 XML 的注释。理想情况下,我会像这样使用 @Resource 和 SpEL 的组合:
@Resource(type="#{myProperties['enabled.subtype']}")
SomeInterface foo;
我从包含以下文件的文件中加载了 myProperties 和 PropertiesFactoryBean 或 <util:properties>:
enabled.type = com.mycompany.SomeClassA; // which implements SomeInterface
这不起作用,因为 type 的参数必须是文字,即不允许 SpEL。这里的最佳做法是什么?
更新:请看下面我的回答。
【问题讨论】:
标签: java spring configuration dependency-injection annotations