Bean初始化失败; ConversionNotSupportedException [英] Initialization of bean failed; ConversionNotSupportedException

查看:754
本文介绍了Bean初始化失败; ConversionNotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个较高的层次结构上下文,它在服务器启动时(tomcat)得到以下bean:

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>

该bean的类('RubricsServiceImpl')实现了一个称为RubricsService的API接口...好。

That bean's class ('RubricsServiceImpl'), implements an API interface called RubricsService ... so far so good. This initializes OK.

在部署Web应用程序时,在层次结构中向下引用其中的bean,位于applicationContext.xml中:

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

所有pom都包含所有依赖项属于,因此没有包会因定义或其他任何原因而饥饿。我一无所知。

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:

推荐答案

Ok... it was a classloader problem. The webapp's classloader was colliding with the container-level one, hence no casting could be done.

所有API .jars都部署到tomcat的shared / lib目录中,所有应用程序都可以访问它们。这是通过设置(Web应用程序的)API模块的pom来完成的:

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>

现在,基于上面的webapp层次结构,专栏有一个针对该webapp的基本pom.xml ,因此必须定义属性,以便其模块的所有子poms共享此依赖项。通过在Web应用程序的基本pom.xml中进行标记,可以执行以下操作:

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>

然后,如果我们需要为该类加载器定义未定义.jar的情况,则只需设置依赖项即可,但是

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.

这篇关于Bean初始化失败; ConversionNotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆