Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 48961 invoked from network); 20 Sep 2006 12:34:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Sep 2006 12:34:58 -0000 Received: (qmail 34047 invoked by uid 500); 20 Sep 2006 12:34:52 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 33934 invoked by uid 500); 20 Sep 2006 12:34:51 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 33900 invoked by uid 99); 20 Sep 2006 12:34:51 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Sep 2006 05:34:51 -0700 Authentication-Results: idunn.apache.osuosl.org header.from=riceyeh@gmail.com; domainkeys=good X-ASF-Spam-Status: No, hits=0.9 required=5.0 tests=DNS_FROM_RFC_ABUSE,HTML_20_30,HTML_MESSAGE,RCVD_BY_IP DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 Received: from ([64.233.166.183:58857] helo=py-out-1112.google.com) by idunn.apache.osuosl.org (ecelerity 2.1 r(10620)) with ESMTP id 36/47-00532-76531154 for ; Wed, 20 Sep 2006 05:34:48 -0700 Received: by py-out-1112.google.com with SMTP id c59so365382pyc for ; Wed, 20 Sep 2006 05:34:45 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=qDK6TuKFz4yv4xqOrIULGH5fcmScixKhh9XD2Sv56Lbn0k5SglJ3SoapYB7AKyy0PC+Ox2oJbIcRx/2jxGvQcYky6FIrl852TWo1RoV31oJs/uc5afIvLfoOYO0H1d37V8vbor6uKuCHrWzpb5uRVkJbh625h8eh+zY3q0cZJDM= Received: by 10.35.88.17 with SMTP id q17mr13854321pyl; Wed, 20 Sep 2006 05:34:44 -0700 (PDT) Received: by 10.35.134.13 with HTTP; Wed, 20 Sep 2006 05:34:44 -0700 (PDT) Message-ID: <47f71d940609200534j36700c9dj5522b305b4527a3f@mail.gmail.com> Date: Wed, 20 Sep 2006 20:34:44 +0800 From: "Rice Yeh" To: dev@cocoon.apache.org Subject: Re: ClassCastException becuase of different classloaders for a bean weaving by springframework In-Reply-To: <47f71d940609200359p5b6b2da6me1a82d885a6aee4d@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_6540_1361432.1158755684711" References: <47f71d940609200359p5b6b2da6me1a82d885a6aee4d@mail.gmail.com> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_6540_1361432.1158755684711 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 wrote: > > Hi, > I have a bean created thru. springframeowrk in cocoon. The bean needs 3 > arguments in its contructor to create it as below: > > > > ref="persistenceAdapter"/> > static-field="java.util.Locale.TAIWAN"/> > > > > > > > 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 > ------=_Part_6540_1361432.1158755684711 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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

------=_Part_6540_1361432.1158755684711--