元素“value”不能包含子元素“object”,因为父元素的内容模型仅为文本

时间:2011-05-23 08:35:09

标签: spring.net

我有一个IDictionary类型的属性,其键类型和值类型不是字符串。在Internet和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',因为父元素元素的内容模型仅限文本。

我的配置中有什么问题吗?

1 个答案:

答案 0 :(得分: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>