2012-04-23 35 views
0

我用Spring.Net編寫了應用程序。當我嘗試打電話給GetObject的(「...」)的Spring.Net的我有一個例外:彈簧投擲錯誤找不到對象的定義

沒有名爲‘SystemConfiguration_Workspace_NewWorkspaceAction’對象定義爲:無法找到對象[SystemConfiguration_Workspace_NewWorkspaceAction]

定義

但我在我的XML中有一個名爲'SystemConfiguration_Workspace_NewWorkspaceAction'的對象。

<?xml version="1.0" encoding="utf-8" ?> 
<spring> 

<typeAliases> 
<alias name="ContextMenuItemModelAlias" type="ElmoMotionControl.View.Model.ContextMenuItemModel, ElmoMotionControl.View.Model"/> 
</typeAliases> 

<objects xmlns="http://www.springframework.net" > 

<!--<description>An example that demonstrates simple IoC features.</description>--> 

<object id="WorkspaceTreeModel" type="ElmoMotionControl.View.Model.ContextMenuModel, ElmoMotionControl.View.Model" > 
    <property name="ContextMenus" ref="WorkspaceTreeModelDicProp"/> 
</object> 

<!-- _______________________The dictionary item______________________ --> 
<object id ="WorkspaceTreeModelDicProp" type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;ContextMenuItemModelAlias>>>"> 
    <constructor-arg> 
     <dictionary key-type="string" value-type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;ContextMenuItemModelAlias>>"> 
     <entry key="SystemConfiguration_Workspace" value-ref="SystemConfiguration_Workspace"/> 
     </dictionary> 
    </constructor-arg> 
</object> 
. 
. 
. 
</objects> 
</spring> 

可能是什麼問題?

+0

我只看到一個'SystemConfiguration_Workspace'而沒有'SystemConfiguration_Workspace_NewWorkspaceAction'對象定義。 – Marijn 2012-04-23 12:17:08

+0

對不起!我試着用GetObject(「WorkspaceTreeModel」) 和我得到了同樣的錯誤(與「WorkspaceTreeModel」)。 – 2012-04-23 12:25:02

+0

難道這是'SystemConfiguration_Workspace'有一個屬性或構造函數配置爲'SystemConfiguration_Workspace_NewWorkspaceAction',這是丟失? – Marijn 2012-04-23 12:39:40

回答

0

這是我的整個XML:

<?xml version="1.0" encoding="utf-8" ?> 
<spring> 
    <typeAliases> 
     <alias name="ContextMenuItemModelAlias" type="ElmoMotionControl.View.Model.ContextMenuItemModel, ElmoMotionControl.View.Model"/> 
    </typeAliases> 

    <objects xmlns="http://www.springframework.net" > 
    <object id="WorkspaceTreeModel" type="ElmoMotionControl.View.Model.ContextMenuModel, ElmoMotionControl.View.Model" > 
     <property name="ContextMenus" ref="WorkspaceTreeModelDicProp"/> 
    </object> 

<!-- _______________________The dictionary item______________________ --> 
    <object id ="WorkspaceTreeModelDicProp" type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;ContextMenuItemModelAlias>>>"> 
     <constructor-arg> 
     <dictionary key-type="string" value-type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;ContextMenuItemModelAlias>>"> 
     <entry key="SystemConfiguration_Workspace" value-ref="SystemConfiguration_Workspace"/> 
     </dictionary> 
    </constructor-arg> 
</object> 

<!--____________Context Menu Items Lists_______________--> 

<object id="SystemConfiguration_Workspace" type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;ContextMenuItemModelAlias>>"> 
    <constructor-arg> 
     <dictionary key-type="string" value-type="System.Collections.Generic.List&lt;ContextMenuItemModelAlias>"> 
      <entry key="SystemConfiguration_Workspace_NewWorkspace" value-ref="SystemConfiguration_Workspace_NewWorkspace1"/> 
     </dictionary> 
    </constructor-arg> 
</object> 

<object id="SystemConfiguration_Workspace_NewWorkspace1" type="System.Collections.Generic.List &lt;ContextMenuItemModelAlias>"> 
    <constructor-arg> 
     <list element-type="ContextMenuItemModelAlias"> 
      <ref object="SystemConfiguration_Workspace_NewWorkspace"/> 
     </list> 
    </constructor-arg> 
</object> 

<!--_____________________Contecxt Menu Items_______________________--> 
<object id="SystemConfiguration_Workspace_NewWorkspace" type="ContextMenuItemModelAlias"> 
    <constructor-arg name="name" value="SystemConfiguration_Workspace_NewWorkspace"/> 
    <constructor-arg name="isEnable" value="true"/> 
    <constructor-arg name="action" ref="SystemConfiguration_Workspace_NewWorkspaceAction"/> 
</object> 

<!--_________________________Actions____________________________--> 
<object id="SystemConfiguration_Workspace_NewWorkspaceAction" type="ElmoMotionControl.Activity.Action.SystemConfigurationActivitySelectionAction, ElmoMotionControl.Activity.Action"/> 
</objects> 
</spring> 

「SystemConfiguration_Workspace」 是在XML對象。我希望Spring.Net將創建一個實例。 我不認爲SystemConfiguration_Workspace有一個配置爲SystemConfiguration_Workspace_NewWorkspaceAction的屬性或構造函數,它缺失。

+0

謝謝!我不知道有什麼問題,但是我在每個級別上課。一個包含List的類,一個包含字符串和最後一個類的字典以及一個包含字符串和最後一個類的類。爲這些類創建XML非常簡單。 Marijn,非常感謝您的幫助和寬容。對此,我真的非常感激。 – 2012-04-24 07:02:52

+0

不客氣。請接受你自己的回答,以便大家都知道你的問題已經解決了。在SO允許你接受你自己的答案之前可能需要一兩天的時間。 – Marijn 2012-04-24 07:11:44

+0

O.K 謝謝 美好的一天 – 2012-04-24 08:46:38

0

謝謝,我成功解決了我的問題

我不知道是什麼問題,但我沒有一流的各個層面。

一個包含List的類,一個包含字符串和最後一個類的類以及一個包含字符串和最後一個類的類。

創建該類的XML很簡單。