why Mixing Spring AOP proxy mechanisms (CGLIB and JDKDynmic) for dependent beans does not work -


i have 2 public classes configured follows in spring application context:

public class loaderrordata{   private exceptiondata exceptiondata;   public loaderrordata() { }    // reminder }  public class exceptiondata implements serializable{   private resource exceptiondataresource;   public exceptiondata() { }    // reminder } 

spring applicationcontext.xml :

<beans:bean id="loaderrordata" class="com.startup.loaderrordata" init-method="startup">   <beans:property name="exceptiondata" ref="exceptiondata"/>  </beans:bean>  <beans:bean id="exceptiondata" class="com.server.exceptiondata" init-method="startup">   <beans:property name="exceptiondataresource" value="classpath:${exception.datafile.path}"/> </beans:bean> 

it gives following exception while initializing :

oct 07, 2013 1:45:21 pm org.apache.catalina.core.standardcontext listenerstart severe: exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener org.springframework.beans.factory.beancreationexception: error creating bean name 'loaderrordata' defined in class path resource [spring/startup-config.xml]: initialization of bean failed; nested exception org.springframework.beans.conversionnotsupportedexception: failed convert property value of type 'com.sun.proxy.$proxy12 implementing java.io.serializable,org.springframework.aop.springproxy,org.springframework.aop.framework.advised' required type 'com.server.iicexceptiondata' property 'exceptiondata'; nested exception java.lang.illegalstateexception: cannot convert value of type [com.sun.proxy.$proxy12 implementing java.io.serializable,org.springframework.aop.springproxy,org.springframework.aop.framework.advised] required type [com.server.iicexceptiondata] property 'exceptiondata': no matching editors or conversion strategy found @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:527) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:456) @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:294) @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:225) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:291) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:193) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:609) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:918) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:469) @ org.springframework.web.context.contextloader.configureandrefreshwebapplicationcontext(contextloader.java:383) @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:283) @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:111) @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4723) @ org.apache.catalina.core.standardcontext$1.call(standardcontext.java:5226) @ org.apache.catalina.core.standardcontext$1.call(standardcontext.java:5221) @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:334) @ java.util.concurrent.futuretask.run(futuretask.java:166) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:724) caused by: org.springframework.beans.conversionnotsupportedexception: failed convert property value of type 'com.sun.proxy.$proxy12 implementing java.io.serializable,org.springframework.aop.springproxy,org.springframework.aop.framework.advised' required type 'com.server.iicexceptiondata' property 'exceptiondata'; nested exception java.lang.illegalstateexception: cannot convert value of type [com.sun.proxy.$proxy12 implementing java.io.serializable,org.springframework.aop.springproxy,org.springframework.aop.framework.advised] required type [com.server.iicexceptiondata] property 'exceptiondata': no matching editors or conversion strategy found @ org.springframework.beans.beanwrapperimpl.convertifnecessary(beanwrapperimpl.java:485) @ org.springframework.beans.beanwrapperimpl.convertforproperty(beanwrapperimpl.java:516) @ org.springframework.beans.beanwrapperimpl.convertforproperty(beanwrapperimpl.java:510) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.convertforproperty(abstractautowirecapablebeanfactory.java:1406) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1365) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1118) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:517) ... 19 more caused by: java.lang.illegalstateexception: cannot convert value of type [com.sun.proxy.$proxy12 implementing java.io.serializable,org.springframework.aop.springproxy,org.springframework.aop.framework.advised] required type [com.server.iicexceptiondata] property 'exceptiondata': no matching editors or conversion strategy found @ org.springframework.beans.typeconverterdelegate.convertifnecessary(typeconverterdelegate.java:241) @ org.springframework.beans.beanwrapperimpl.convertifnecessary(beanwrapperimpl.java:470) ... 25 more

but when put

<aop:scoped-proxy proxy-target-class="true"/> 

in exceptiondata bean configuration or if remove

implements serializable 

from exceptiondata

exception goes away. aop pointcut follows:

expression="execution(* com..*(..))" 

it seems spring trying create cglib proxy bean loaderrordata (as not implement interface) , jdkdynamicproxy dependency exceptiondata (as implement interface serializable). , not able so. because when tell spring create cglib proxy explicitly exceptiondata works fine. why so? why not able create jdkdynamic proxy bean(exceptiondata) dependency of bean (loaderrordata) trying create cglib proxy? according documentation says spring detect automatically.

actually situation describe happening.

loaderrordata going cglib proxy (due no interfaces. exceptiondata going jdk dynamic proxy.

however loaderrordata expects bean of type exceptiondata, jdk dynamic proxy serializable (as proxy interfaces , not classes). never possible cast instance of exceptiondata , hence loading of context fail. (this stacktrace tells error message).

it work if forcing class based proxies or removing serializable interface. either way lead classbased proxy.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -