Dhanji在其book about Dependnecy Injection中鼓励在命名spring bean时使用名称空间。Spring:使用ID中的名称空间的bean与SPeL冲突
Qutation从书:
我也强烈鼓励命名空间的使用,例如,“set.BinaryTree”和 “set.HashTable”,这是更好的阅读和理解比“binaryTreeSet” 和“hashTableSet”。命名空间是您的关键空间的更优雅和自然的命名法,并且明显比字符串分组的大写字母 更可读。
现在听起来很合理。但是从SPeL开始,就产生了冲突。 奥兹用于黑色安息日玩,所以每一个乐队成员,我将使用BS namespance在bean名字像这样:
<bean id="bs.ozzy"
class="sk.spring.idol.annotation.Instrumentalist"
p:song="Sabbath Bloody Sabbath" />
现在我有黑色安息日的其他成员,谁将会对注入价值歌曲名称使用SpEL。无论歌曲播放奥兹也将发挥我的新成员(比方说托尼):
public class Instrumentalist implements Performer {
@Value("#{bs.ozzy.song}")
private String song;
// blabla other stuff, getters setters and so on
}
现在我将要得到的是...
Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'bs' cannot be found on object
现在什么?有没有什么方法可以将文本转义为“这是bean名称,并且不会将其评估为属性”?
注:
- 的代码示例由Dhanji的书的启发。
- 我承认 - 我没有阅读规划环境地政司整个文档,可能的解决方案是非常简单得多
我同意,命名空间不应该有 “”作为分隔符,如果使用SPeL的话。但是你知道,我们有很大的代码库,现在我们不应该使用SPeL或重写这个东西。 :/ – Xorty