Spring.NET问题 配置中的标签
根据 Spring.NET 框架附带的帮助文件,您可以使用“idref”标签和“local”属性来注入本地文件中定义的依赖项。
我一直在尝试这样做,但没有成功,希望有人有经验可以帮助我。
下面是配置中的一个片段,我将其作为构造函数参数传递,但我也尝试将其设置为属性。 两种方法似乎都会产生相同的错误。
<object id="theTargetObject" type="TestClassLibrary.TargetObject, TestClassLibrary"/>
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<constructor-arg name="myClass">
<idref local="theTargetObject"/>
</constructor-arg>
</object>
创建上下文'spring.root'时出错:创建在'文件[C:\Test\TestApp\bin\Debug\my.config.xml]'中定义的名称为'theClientObject'的对象时出错:通过索引为0的构造函数参数表达的依赖关系不满足类型 [TestClassLibrary.TargetObject] :无法将构造函数参数值 [theTargetObject] 转换为所需类型 [TestClassLibrary.TargetObject]:无法将类型 [System.String] 的属性值转换为属性“”所需的类型 [TestClassLibrary.TargetObject]。
According to the help file that comes with the Spring.NET framework, you can inject a dependancy defined in the local file by using an 'idref' tag along with a 'local' attribute.
I have been trying to do this with no success and was hoping someone had the experience to help me out.
Below I have a snippet from the config where I am passing it as a constructor argument, but I have tried setting it as a property as well. Both methods seem to yield the same error.
<object id="theTargetObject" type="TestClassLibrary.TargetObject, TestClassLibrary"/>
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<constructor-arg name="myClass">
<idref local="theTargetObject"/>
</constructor-arg>
</object>
Error creating context 'spring.root': Error creating object with name 'theClientObject' defined in 'file [C:\Test\TestApp\bin\Debug\my.config.xml]' : Unsatisfied dependency expressed through constructor argument with index 0 of type [TestClassLibrary.TargetObject] : Could not convert constructor argument value [theTargetObject] to required type [TestClassLibrary.TargetObject] : Cannot convert property value of type [System.String] to required type [TestClassLibrary.TargetObject] for property ''.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜 gef 的方向是正确的,但在粘贴代码片段时意外地混淆了它。您正在寻找 ; 元素:
其简写符号为:
hth,
埃里希
I guess gef was on the right way but accidentially mixed it up when pasting the snippet.You are looking for the <ref> element:
the shorthand notation for this is:
hth,
Erich
请查看帖子 http://forum.springsource.org/showthread.php?t= 14211
Please view the post http://forum.springsource.org/showthread.php?t=14211