【问题标题】:The element 'value' cannot contain child element 'object' because the parent element's content model is text only元素“值”不能包含子元素“对象”,因为父元素的内容模型仅为文本
【发布时间】:2011-05-23 08:35:08
【问题描述】:

我有一个IDictionary 类型的属性,其键类型和值类型不是字符串。互联网上和 Spring.Net 中给出的大多数示例都使用字符串作为类型之一。

这里是配置设置:

<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”,因为父元素元素的内容模型仅为文本。

我的配置有问题吗?

【问题讨论】:

    标签: spring.net


    【解决方案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>
    

    【讨论】:

    • 使用 成功了。
    猜你喜欢
    • 2010-12-17
    • 2020-09-10
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多