cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rice Yeh" <rice...@gmail.com>
Subject Re: ClassCastException becuase of different classloaders for a bean weaving by springframework
Date Wed, 20 Sep 2006 12:34:44 GMT
Seems jetty6:run will automatically add all dependences in pom.xml to
WEB-INF/lib. I get the following information by passing -X to mvn command.

[INFO] Context path = /
[DEBUG] Adding artifact hibernate-3.2.0.cr2.jar for WEB-INF/lib
[DEBUG] Adding artifact jakarta-bcel-20040329.jar for WEB-INF/lib
[DEBUG] Adding artifact excalibur-logger-2.1.jar for WEB-INF/lib
[DEBUG] Adding artifact commons-logging-1.0.4.jar for WEB-INF/lib
[DEBUG] Adding artifact xs-persistence-hibernate-1.0-SNAPSHOT.jar for
WEB-INF/lib
....

On 9/20/06, Rice Yeh <riceyeh@gmail.com> wrote:
>
> Hi,
>   I have a bean created thru. springframeowrk in cocoon. The bean needs 3
> arguments in its contructor to create it as below:
>
>     <bean id="platform" class="xs.school.Platform" scope="singleton">
>         <constructor-arg type="java.lang.String" value="development"/>
>         <constructor-arg type="xs.persistence.Adapter"
> ref="persistenceAdapter"/>
>         <constructor-arg type=" java.util.Locale"><util:constant
> static-field="java.util.Locale.TAIWAN"/></constructor-arg>
>     </bean>
>
>     <bean id="persistenceAdapter" class="xs.selection.HibernateAdapter ">
>         <property name="settings" value="hibernate.cfg.xml"/>
>     </bean>
>
> I find xs.persistence.Adapter 's (which is an interface) classloader is
> WebAppClassLoader. The real adapter implemenation is called HibernateAdapter
> whose classloader is DefaultClassLoader. So a ClassCastException is thrown
> when assigning the instance of HibernateAdapter (which implements Adapter,
> surely) to the second argument shown beflow. Adapter and HibernateAdapter
> are in two different jars but both are in WEB-INF/cocoon/lib. Should not all
> classes in jars under WEB-INF/cocoon/lib loaded by the same classloader
> (DefaultClassLoader)?
>
> Caused by:
> org.springframework.beans.factory.UnsatisfiedDependencyException: Err
> or creating bean with name 'platform' defined in URL
> [file:C:/tmp/cocoon/xs-scho
> ol-cocoon/src/main/resources/META-INF/spring/application.xml]: Unsatisfied
> depen
> dency expressed through constructor argument with index 1 of type [
> xs.persistenc
> e.Adapter]: Could not convert constructor argument value [
> xs.selection.Hibernate
> Adapter@779f5e] to required type [xs.persistence.Adapter ]: Failed to
> convert val
> ue of type [xs.selection.HibernateAdapter] to required type [
> xs.persistence.Adap
> ter]; nested exception is java.lang.IllegalArgumentException: No matching
> editor
> s or conversion strategy found
>         at
> org.springframework.beans.factory.support.ConstructorResolver.createA
> rgumentArray(ConstructorResolver.java:375)
>         at
> org.springframework.beans.factory.support.ConstructorResolver.autowir
> eConstructor( ConstructorResolver.java:126)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:548)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBean
> Factory.createBean(AbstractAutowireCapableBeanFactory.java:352)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
> ject(AbstractBeanFactory.java:240)
>         at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
> y.getSingleton(DefaultSingletonBeanRegistry.java:132)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
> (AbstractBeanFactory.java:237)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean
> (AbstractBeanFactory.java:153)
>         at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.
> preInstantiateSingletons(DefaultListableBeanFactory.java:254)
>         at
> org.springframework.context.support.AbstractApplicationContext.refres
> h(AbstractApplicationContext.java:337)
>         at
> org.springframework.web.context.support.AbstractRefreshableWebApplica
> tionContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
>         at
> org.springframework.web.context.ContextLoader.createWebApplicationCon
> text(ContextLoader.java:246)
>         at
> org.springframework.web.context.ContextLoader.initWebApplicationConte
> xt(ContextLoader.java:184)
>         at
> org.springframework.web.context.ContextLoaderListener.contextInitiali
> zed(ContextLoaderListener.java:49)
>         at org.apache.cocoon.bootstrap.servlet.ShieldingListener.invoke
> (Shieldin
> gListener.java:151)
>         ... 32 more
>
>
> Rice
>

Mime
View raw message