问题
I have a higher hierarchy context, which on server startup (tomcat) gets the following bean:
<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>
That bean's class ('RubricsServiceImpl'), implements an API interface called RubricsService ... so far so good. This initializes OK.
Down the hierarchy, when webapps are being deployed, on of these references this bean in 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>
While deploying the app, the following exception is thrown:
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
All the poms contain all the dependencies where they belong so no package starves from definitions or anything. I am clueless.
Could this be a Class Loader issue?
The following is my applications structure:
回答1:
Ok... it was a classloader problem. The webapp's classloader was colliding with the container-level one, hence no casting could be done.
All the API .jars are deployed to tomcat's shared/lib directory for all apps to be able to access them. This is done by setting in the pom of the API module (of the webapp) :
<properties>
<deploy.target>shared</deploy.target>
</properties>
Now, based on the hierarchy of the webapp above, rubrics has a base pom.xml for the webapp, and in this, it is necessary to define the property so all the children poms of its modules, shared this dependencies. By markind in the base pom.xml of the webapp the following:
<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>
Then, we just set the dependency if we need it with no .jar defined for that classloader, but to be provided by the container later on.
This was my interpretation after solving the issue. Please feel free to correct/add/enrich.
来源:https://stackoverflow.com/questions/33501165/initialization-of-bean-failed-conversionnotsupportedexception