开发者

Injecting Spring Spel Expressions into bean properties

开发者 https://www.devze.com 2023-03-19 23:40 出处:网络
How can I inject a String meant to be a spel expression into an app context bean property without having the context interpret the string property as a spel resolvable value.

How can I inject a String meant to be a spel expression into an app context bean property without having the context interpret the string property as a spel resolvable value.

<bean id="x" p:spelExpression="${#code}/${#value}"/>

I want the the class's setter property to take a string argument and creates a reusable SpelExpression as a private property of the bean, however, the spring application context appears to be recognizing the #variableName as spel expressions and attempting to interpret the expression at initialization time.

I find Spel interpretation to be very useful, but would like to to use spel internally as well, with expression injection into my own beans.

Is i开发者_高级运维t possible to disable the Spel Interpretation of for a bean, or even for a whole context file (maybe with some namespace shenanigans) without having to disable or modify spel expression resolution for the whole application context.


The #{...} are markers for spel interpreter in xml context.

I don't undestand : ${#code}/${#value}. Good is #{code/value}, as I understand things, if code and value are id.

So, if you want a spel expression without interpret it, put string code/value in xml.

0

精彩评论

暂无评论...
验证码 换一张
取 消