2015-11-03 195 views
0

我有一個更高的層次方面,它在服務器啓動時(Tomcat)的獲取以下豆:bean初始化失敗; ConversionNotSupportedException

<bean id="org.sakaiproject.rubrics.api.rubric.RubricsService" class="org.sakaiproject.rubrics.impl.RubricsServiceImpl" 
    init-method="init" 
    singleton="true"> 
    <property name="rubricsLogic" ref="org.sakaiproject.rubrics.logic.RURubricLogic" /> 
    <property name="externalLogic" ref="org.sakaiproject.rubrics.api.rubric.ExternalLogic" /> 
</bean> 

這bean類(「RubricsServiceImpl」),實現了一個名爲RubricsService的API接口......到目前爲止一切好。這初始化確定。

下層次結構,當web應用被部署,在這些引用這個bean在applicationContext.xml中的:

<bean id="org.sakaiproject.rubrics.tool.RubricsTool" class="org.sakaiproject.rubrics.tool.RubricsTool"> 
    <property name="rubricsService" ref="org.sakaiproject.rubrics.api.rubric.RubricsService" /> 
</bean> 

在部署應用程序,以下異常被拋出:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.rubrics.tool.RubricsTool' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: 
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.sakaiproject.rubrics.impl.RubricsServiceImpl' to required type 'org.sakaiproject.rubrics.api.rubric.RubricsService' for property 'rubricsService'; nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [org.sakaiproject.rubrics.impl.RubricsServiceImpl] to required type [org.sakaiproject.rubrics.api.rubric.RubricsService] for property 'rubricsService': 
no matching editors or conversion strategy found 

所有的poms包含所有依賴關係他們所屬的地方,因此沒有包裹從定義或任何東西中匱乏。我無能爲力。

這可能是一個類加載器的問題?

以下是我的應用程序結構:

enter image description here

回答

0

好吧......這是一個類加載器的問題。 Web應用程序的類加載器與容器級別衝突,因此不能執行轉換。

所有API .jars都被部署到tomcat的shared/lib目錄中,以便所有應用程序都能夠訪問它們。這是通過(的web應用程序)在API模塊的POM設定完成:

<properties> 
    <deploy.target>shared</deploy.target> 
</properties> 

現在,基於上述的web應用的層次結構,量規具有用於web應用程序的基座的pom.xml,並且在該,所以有必要定義屬性,使其模塊中的所有子poms都共享這些依賴關係。通過在Web應用程序的基本的pom.xml markind如下:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
     <groupId>org.sakaiproject.rubrics</groupId> 
      <artifactId>rubrics-api</artifactId> 
      <version>10.4</version> 
      <scope>provided</scope> <!-- from the CONTAINER --> 
     </dependency> 
     <dependency> 
      <groupId>org.sakaiproject.rubrics</groupId> 
      <artifactId>rubrics-impl</artifactId> 
      <version>10.4</version> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

然後,我們剛剛設置的依賴,如果我們沒有爲類加載器定義的.jar需要它,而是要由容器以後提供。

這是我解釋問題後的解釋。請隨時糾正/添加/充實。