【发布时间】:2015-01-15 17:14:43
【问题描述】:
我们有一些遗留代码,我正试图找出一种清理方法。我想到的一个解决方案是,也许我可以根据给定的枚举值注入一个自定义处理程序。我可以根据枚举来限定注入吗?我可能在想这样的事情(伪代码)
@Service(MyEnum.MYVALUE, MyEnum.MYOTHERVALUE) // produces a handler given these enums
public class MyHandler { ... }
@Service(MyEnum.ANOTHERVALUE)
public class AnotherHandler {... }
// .... some mystical way of telling spring what my current enum context is so I can get the right handler
【问题讨论】:
-
您可以从下面的链接concretepage.com/spring/spring_custom_qualifier_annotation 中找到自定义限定符的示例(部分:使用 Java 配置的带有 value() 方法的自定义限定符)
标签: java spring enums spring-3