引用一个对象定义Spring.NET表达 [英] Spring.NET Expression that References an Object Definition
问题描述
我想引用我在Spring配置文件从表达式中定义的另一个对象。具体来说,我想填充在那里我调用一个方法,然后从该方法返回的对象上的属性表达式的值的属性。
我试过以下(名称已更改):
<预类=郎咸平的XML prettyprint-覆盖>
<属性名=NullableIntProperty
表达=#{} Some.Object.Id获得()NullableIntValue/>
其中, Some.Object.Id
是一个参考我在一个配置文件中定义,如其他对象:
<预类=郎咸平的XML prettyprint-覆盖>
<对象ID = Some.Object.Id...>
但我的应用程序无法启动与解析异常期待冒号,发现'}
。我认为这是期待一个命名空间,但是我没有找到这个文件。
我试过几件事情,但无论我打了一个死胡同。我最初尝试的 MethodInvokingFactoryObject
和 PropertyRetrievingFactoryObject
这是我们在其他地方不可为空的类型使用,但这种组合失败对于那些实际上nullables 空
由于Spring看到一个对象工厂返回空
作为失败(通常是这样)
您可以使用 @(对象ID-这里)
表达式语法检索Spring上下文对象使用表达式:
<预类=郎咸平的XML prettyprint-覆盖>
<属性名=NullableIntProperty
表达的影响=@(Some.Object.Id).PropertyOnSomeObject/>
I'm trying to reference another object I've defined in a Spring config file from within an expression. Specifically, I'm trying to populate a property with the value of an expression where I call a method and then a property on the object returned from that method.
I've tried the following (names have been changed):
<property name="NullableIntProperty"
expression="#{Some.Object.Id}.Get().NullableIntValue"/>
where Some.Object.Id
is a reference to another object I have defined in a config file such as:
<object id="Some.Object.Id" ... >
but my app fails to start with the parsing exception expecting "COLON", found '}'
. I think it's expecting a namespace, but I'm not finding the documentation for this.
I've tried several things, but everywhere I hit a dead end. I originally tried a combination of the MethodInvokingFactoryObject
and PropertyRetrievingFactoryObject
which we use in other places for non-nullable types, but this fails for nullables that are actually null
since Spring sees an object factory returning null
as a failure (which it usually is).
You can use the @(object-id-here)
expression syntax to retrieve an object from the Spring context using an expression:
<property name="NullableIntProperty"
expression="@(Some.Object.Id).PropertyOnSomeObject"/>
这篇关于引用一个对象定义Spring.NET表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!