Spring.NET Expression that References an Object Definition

南笙酒味 提交于 2020-01-04 06:06:01

问题


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


回答1:


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"/>



回答2:


Changing # to $ should fix it, I believe.



来源:https://stackoverflow.com/questions/1406925/spring-net-expression-that-references-an-object-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!