引用对象定义的 Spring.NET 表达式
我试图从表达式中引用我在 Spring 配置文件中定义的另一个对象。具体来说,我尝试使用调用方法的表达式的值填充属性,然后填充从该方法返回的对象上的属性。
我尝试了以下操作(名称已更改):
<property name="NullableIntProperty"
expression="#{Some.Object.Id}.Get().NullableIntValue"/>
其中 Some.Object.Id
是对我在配置文件中定义的另一个对象的引用,例如:
<object id="Some.Object.Id" ... >
但我的应用程序无法从解析异常开始期望“COLON”,发现“}”
。我认为它需要一个命名空间,但我没有找到这方面的文档。
我尝试过很多事情,但到处都陷入了死胡同。我最初尝试了 MethodInvokingFactoryObject
和 PropertyRetreeringFactoryObject
的组合,我们在其他地方将其用于不可为空类型,但是对于实际上为 null
的可空值,这会失败。 code> 因为 Spring 认为对象工厂返回 null
作为失败(通常是这样)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
@(object-id-here)
表达式语法 使用表达式从 Spring 上下文中检索对象:You can use the
@(object-id-here)
expression syntax to retrieve an object from the Spring context using an expression:我相信将 # 更改为 $ 应该可以解决它。
Changing # to $ should fix it, I believe.