Spring.net - PropertyRetreeringFactoryObject - 属性为空
为了解决这个问题,我正在采取看看我们的 spring.net 配置是如何工作的。
根本问题来自此代码片段:
<object name="someObject" singleton="false" type="SomeType.someObject, SomeAssembly">
<constructor-arg name="authSession">
<object type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
<property name="TargetObject" ref="AuthSessionManager" />
<property name="TargetProperty" value="CurrentAuthSession" />
</object>
</constructor-arg>
</object>
在用户未登录的情况下,AuthSessionManager.CurrentAuthSession
将为空。在这种情况下,Spring.NET 会抛出异常:“Factory object returned null object”。
在这种情况下,我如何告诉 Spring 空对象是可以接受的?
In an attempt to resolve this question, I'm taking a look at how our spring.net configuration works.
The root problem comes from this snippet:
<object name="someObject" singleton="false" type="SomeType.someObject, SomeAssembly">
<constructor-arg name="authSession">
<object type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
<property name="TargetObject" ref="AuthSessionManager" />
<property name="TargetProperty" value="CurrentAuthSession" />
</object>
</constructor-arg>
</object>
In a case where a user is not logged in, AuthSessionManager.CurrentAuthSession
will be null. When that is the case, Spring.NET throws an exception: "Factory object returned null object".
How can I tell Spring that the null object is acceptable in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 表达式从spring context 在你的构造函数参数中,类似于:
允许表达式计算为 null,所以你不必告诉 Spring 任何东西。
这在一个简单的情况下对我有用(没有嵌套上下文)。
You can use an expression to retrieve an object from the spring context in your constructor argument, something like:
Expressions are allowed to evaluate to null, so you don't have to tell Spring anything.
This worked for me in a simple case (no nested contexts).