Announcement Announcement Module
Collapse
No announcement yet.
getting TypeMismatchException when creating a bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • getting TypeMismatchException when creating a bean

    I'm having deficulties when I'm creting a bean that has one property that is used as a poincut. I'm using autoproxy.

    right now I have a BeanA that has a property that references Bean B and I declared a pointcut as a method in BeanB, when BeanA is created and the property is being set to Bean B I'm getting a TypeMismatchException that can not cast from Proxy to BeanB.

    This is the error I'm getting:

    PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Fail
    ed to convert property value of type [$Proxy100] to required type [com.myclass.ReceivingHandlerManager] for property 'mrfReceivingHan
    dlerManager'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy100] to required type [com.accenture.adsj.soa.mrf.hand
    lers.ReceivingHandlerManager] for property 'mrfReceivingHandlerManager': no matching editors or conversion strategy found

    Please help!!!!!!!! If I use another bean that is not being referenced by another bean it works perfectly.

  • #2
    How do you create your proxies?

    At least you seem to have JDK dynamic proxies without programming to interfaces. Either change this or switch to CGLib proxies via the property proxy-target-class="true".

    It's also always good to search the forum for possible solutions to your problem. This is one of the most frequently asked questions.

    Jörg

    Comment


    • #3
      HI


      Thanks a lot for your quick response.... I tried that approch proxy-target-class="true". and I got a different error message, actually I read that in one of the threads here and it was your advise.

      I'm using autoproxy that way I don;t have to declare a proxy for each bean I'm using, I think that's going to be the solution unfortunately

      Any other idea?

      Comment


      • #4
        Can you post your config and a simple test case, if possible, around [ code][ /code] tags ?

        Comment


        • #5
          Now I changed and I'm getting a different error message:

          Code:
          <aop:config>
          		<aop:aspect ref="MyAspect">
          			<aop:around pointcut="execution(* main.ClassA.print())"
          				method="doLog" />
          		</aop:aspect>
          	</aop:config>
          
          	<bean class="main.testClass" id="test">
          		<property name="cl" ref="ClassA"></property>
          	</bean>
          	
          	<bean class="main.Interceptor" id="MyAspect" />
          	
          	<bean id="ClassA"
          		class="org.springframework.aop.framework.ProxyFactoryBean">
          		<property name="target">
          		<bean class="main.ClassA" abstract="false" scope="singleton"
          				lazy-init="default" autowire="default" dependency-check="default">
          		</bean>
          		</property>
          		<property name="proxyTargetClass">
          			<value>true</value>
          		</property>
          	</bean>
          I'm defining the proxy manually and I'm getting this error

          Code:
          INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1ef9157: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJExpressionPointcut,org.springframework.aop.aspectj.AspectJPointcutAdvisor,test,MyAspect,ClassA]; root of factory hierarchy
          Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'test' defined in class path resource [config.xml]: Cannot resolve reference to bean 'ClassA' while setting bean property 'cl'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ClassA': FactoryBean threw exception on object creation; nested exception is org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class $Proxy0]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy0
          Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ClassA': FactoryBean threw exception on object creation; nested exception is org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class $Proxy0]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy0
          Caused by: org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class $Proxy0]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy0
          Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy0
          	at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
          	at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
          	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
          	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
          	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
          	at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
          	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:195)
          	at org.springframework.aop.framework.ProxyFactoryBean.getProxy(ProxyFactoryBean.java:342)
          	at org.springframework.aop.framework.ProxyFactoryBean.getSingletonInstance(ProxyFactoryBean.java:297)
          	at org.springframework.aop.framework.ProxyFactoryBean.getObject(ProxyFactoryBean.java:227)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectFromFactoryBean(AbstractBeanFactory.java:1191)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1162)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:262)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
          	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
          	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1073)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:835)
          	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)
          	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
          	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
          	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
          	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:279)
          	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:360)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
          	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
          	at main.Main.main(Main.java:17)

          Comment


          • #6
            Set proxy-target-class="true" on <aop:config/>.

            Comment


            • #7
              Yes I did that but for some reason it creates a proxy for other classes that are not set up as pointcut and this class has a constructor with one parameter.... and that's when it crashes

              Comment


              • #8
                You have most likely a double-proxying in your context. You need to resolve it.

                Jörg

                Comment

                Working...
                X