Spring.NET Expression that References an Object De

2019-07-12 08:27发布

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).

2条回答
孤傲高冷的网名
2楼-- · 2019-07-12 08:50

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"/>
查看更多
祖国的老花朵
3楼-- · 2019-07-12 08:59

Changing # to $ should fix it, I believe.

查看更多
登录 后发表回答