2011-05-23 93 views
0

我有一個IDictionary類型的屬性,其鍵類型和值類型不是字符串。在互聯網和Spring.Net上給出的大多數例子都使用字符串作爲類型之一。元素'值'不能包含子元素'object',因爲父元素的內容模型僅爲文本

下面是配置設置:

<property name="DirectoryServiceAgents"> 
    <dictionary key-type="OM.ServiceTier.DTO.Transients.AuthenticationDomainIdentifier, OM.ServiceTier" value-type="OM.ServiceTier.Services.User.Internal.IDirectoryServiceAgent, OM.ServiceTier">   
    <entry> 
     <key> 
     <object type="OM.ServiceTier.DTO.Transients.AuthenticationDomainIdentifier, OM.ServiceTier"> 
      <constructor-arg type="string" value="${activeDirectory.Domain}"/> 
     </object> 
     </key> 
     <value> 
     <object type="OM.ServiceTier.Services.User.Internal.DirectoryServiceAgent, OM.ServiceTier"> 
      <property name="LDAPPath" value="${activeDirectory.LDAPPath}"/> 
      <property name="LDAPContainer" value="${activeDirectory.LDAPContainer}"/> 
      <property name="UserName" value="${activeDirectory.UserName}"/> 
      <property name="Password" value="${activeDirectory.Password}"/> 
     </object> 
     </value> 
    </entry> 
    </dictionary> 
</property> 

我正在以下ConfigurationErrorException

錯誤創建上下文 'spring.root':元素的「http://www.springframework .net:value'不能包含子元素'http://www.springframework.net:object',因爲父元素的內容模型僅爲文本。

我的配置有什麼問題嗎?

回答

1

我不確定字典配置是否支持鍵和/或值的inline object definitions。這在documentation on setting collection values中沒有提及。

你能嘗試此配置:

<object> 
    <!-- snip --> 
    <property name="DirectoryServiceAgents"> 
    <dictionary 
     key-type="OM.ServiceTier.DTO.Transients.AuthenticationDomainIdentifier, OM.ServiceTier" 
     value-type="OM.ServiceTier.Services.User.Internal.IDirectoryServiceAgent, OM.ServiceTier">   
     <entry key-ref="authDomainId" value-ref="serviceAgent"/> 
    </dictionary> 
    </property> 
    <!-- snip --> 
</object>  

<object id="authDomainId" 
     type="OM.ServiceTier.DTO.Transients.AuthenticationDomainIdentifier, OM.ServiceTier"> 
    <constructor-arg type="string" value="${activeDirectory.Domain}"/> 
</object> 

<object id="serviceAgent" 
     type="OM.ServiceTier.Services.User.Internal.DirectoryServiceAgent, OM.ServiceTier"> 
    <property name="LDAPPath" value="${activeDirectory.LDAPPath}"/> 
    <property name="LDAPContainer" value="${activeDirectory.LDAPContainer}"/> 
    <property name="UserName" value="${activeDirectory.UserName}"/> 
    <property name="Password" value="${activeDirectory.Password}"/> 
</object> 
+0

使用<進入關鍵-REF = 「authDomainId」 值-REF = 「serviceAgent」/>它的工作。 – Kiru 2011-05-24 12:33:51

相關問題