无法将类型为[java.util.ArrayList]的构造函数参数值转换为必需类型[java.util.List]

时间:2016-04-17 05:01:57

标签: spring

我有一个名为“ request-details-upload.xml ”的弹簧xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    ">

<import resource="classpath:META-INF/jobs/environment.xml" />
<import resource="classpath:META-INF/jobs/clients.xml" />
<import resource="classpath:META-INF/jobs/edx/request-details.xml" />
<import resource="classpath:META-INF/jobs/dynamoDbClients.xml" />

 <bean id="requestDetailsFetchAndDecryptDataDao" class="com.amazon.edx.dao.FetchAndDecryptDataDaoDynamoDbImpl"
 c:dataUploadDao-ref="requestDetailsDataUploadDao"
 c:dataTransformer-ref="requestDetailsDataTransformer" 
 />
 <util:list id="requestDetailsKeyItemAttributesMetadata" value-type="com.amazon.edx.manager.ItemAttributesMetaData">
        <ref bean="RequestId"/>
        <ref bean="RequestDate"/>
 </util:list>

 <util:list id="requestDetailsNonKeyItemAttributesMetadata" value-type="com.amazon.edx.manager.ItemAttributesMetaData">        
        <ref bean="CreatedBy"/>
        <ref bean="UpdatedTime"/>           
</util:list>

 <bean id="RequestId" class="com.amazon.edx.manager.ItemAttributesMetaData" 
    c:itemAttributeName="RequestId"
/> 

   <bean id="RequestDate" class="com.amazon.edx.manager.ItemAttributesMetaData" 
    c:itemAttributeName="RequestDate"
/> 

<bean id="CreatedBy" class="com.amazon.edx.manager.ItemAttributesMetaData" 
    c:itemAttributeName="CreatedBy"
/> 
 <bean id="UpdatedTime" class="com.amazon.edx.manager.ItemAttributesMetaData" 
    c:itemAttributeName="UpdatedTime"
/> 

    <!-- upload manager -->
  <bean id = "requestDetailsDataUploadManager" class ="com.amazon.edx.manager.DataUploadManagerImpl" 
c:fetchAndDecryptDataDao-ref="requestDetailsFetchAndDecryptDataDao"
c:keyAttributes-ref="requestDetailsKeyItemAttributesMetadata"
c:nonKeyAttributes-ref="requestDetailsNonKeyItemAttributesMetadata"
/>

 <bean id = "requestDetailsUploadToEdx" class = "com.amazon.edx.UploadDataToEdx"
c:dataUploadManager-ref ="requestDetailsDataUploadManager"
/>
</beans>

和另一个名为 request-details.xml

的xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:c="http://www.springframework.org/schema/c"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    ">

  <bean id="requestDetailsDataUploadDao" class="com.amazon.edx.dao.DataUploadClientImpl"
 c:someName="xxxxxxxxxx"
 c:otherName="yyyyyyyyy"    
    />

  <util:list id="requestDetailsColumnMetaData" value-type="com.amazon.edx.transformer.ColumnMetaData">
        <ref bean="RequestId"/>
        <ref bean="RequestDate"/>
        <ref bean="CreatedBy"/>
        <ref bean="UpdatedTime"/>            
 </util:list>

  <bean id="RequestId" class="com.amazon.edx.transformer.ColumnMetaData"
    c:attributeName="RequestId"
    c:dataType="VARCHAR2"
    c:columnDisplayName="REQUEST_ID"
   /> 

   <bean id="RequestDate" class="com.amazon.edx.transformer.ColumnMetaData"
    c:attributeName="RequestDate"
    c:dataType="VARCHAR2"
    c:columnDisplayName="REQUEST_DATE"
    />  


   <bean id="CreatedBy" class="com.amazon.edx.transformer.ColumnMetaData"
    c:attributeName="CreatedBy"
    c:dataType="VARCHAR2"
    c:columnDisplayName="CREATED_BY"
    />  
    <bean id="UpdatedTime" class="com.amazon.edx.transformer.ColumnMetaData"
    c:attributeName="UpdatedTime"
    c:dataType="NUMBER"
    c:columnDisplayName="UPDATED_TIME"
    />  

   <bean id="requestDetailsDataTransformer" class="com.amazon.edx.transformer.DataTransformerImpl"
   c:dataFlattener-ref="requestDetailsDataFlattener"
   c:columnMetadata-ref="requestDetailsColumnMetaData"
    c:delimiter="{tabDelimiter}"
     />

   <util:constant id="tabDelimiter"
        static-field="com.amazon.edx.transformer.Delimiters.TAB_DELIMITER"    />

    <bean id="requestDetailsDataFlattener"   class="com.amazon.edx.flattener.JsonDataFlattenerImpl" 
      c:multipleRowColumnName=""
     />
  </beans>

我收到以下错误:

Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestDetailsDataTransformer' defined in class path resource [META-INF/jobs/edx/request-details.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.util.List]: Could not convert constructor argument value of type [java.util.ArrayList] to required type [java.util.List]: Failed to convert value of type 'java.util.ArrayList' to required type 'java.util.List'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.amazon.edx.manager.ItemAttributesMetaData] to required type [com.amazon.edx.transformer.ColumnMetaData]: no matching editors or conversion strategy found

它表示无法从java.util.ArrayList转换为java.util.List。我甚至没有使用java.util.ArrayList。我是Spring的新手,无法理解这个错误的确切原因。

感谢任何帮助。 感谢

2 个答案:

答案 0 :(得分:0)

啊啊......弄明白了这个问题。两个文件的列表中存在的bean ID存在冲突。即使Bean ID位于不同的.xml文件中,它们也应该是唯一的。将一个文件导入其他文件时会发生冲突。

答案 1 :(得分:0)

如果使用List类型依赖项,则由于它是一个接口,因此spring容器将创建其实现类ArrayList的对象。

对于Set类型依赖性,spring容器创建其实现类LinkedHashSet的对象。

对于Map类型依赖性,spring容器创建其实现类LinkedHashMap的对象。

对于Properties类型依赖项,由于它是一个类,因此spring容器仅创建一个Properties类的对象。