Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Core Container

Reply
 
Thread Tools Display Modes
  #1  
Old Jan 9th, 2009, 05:37 PM
AlexElba AlexElba is offline
Junior Member
 
Join Date: Jan 2009
Posts: 2
Question Spring Proxy exception - Proxy13

Hello

I have problem which was not able to solve so far. I am getting Proxy13 exception during execution.

Please can someone help me with solving this?

Here are my classes

Code:
public class MainExecutor {

	DoStuff consumer;

	public static void main() {
		this.consumer = (DoStuff) applicationContext.getBean("doConsumer",
				DoStuff.class);
		ExecutorService executorService = Executors
				.newFixedThreadPool(numOfThreads * 2);
		for (int i = 0; i < numOfThreads; i++) {
			executorService.execute(consumer);
		}
	}
}
Code:
public class DoStuff implements Runnable, Serializable {
	@Override
	@Transactional
	public void run() {
		doLotOfStuff();
	}

	private void doLotOfStuff() {
		System.out.println("Hello world");
	}

}
from Application Context
....
Code:
    <bean id="doConsumer"
        class="player.controller.DoStuff" >
    </bean>
....

After executing main method I am getting folowing exception


Quote:
Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'doConsumer' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy13 implementing java.lang.Runnable,java.io.Serializable,org.spring framework.aop.SpringProxy,org.springframework.aop. framework.Advised] to required type [player.controller.DoStuff] for property 'doConsumer'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy13 implementing java.lang.Runnable,java.io.Serializable,org.spring framework.aop.SpringProxy,org.springframework.aop. framework.Advised] to required type [player.controller.DoStuff] for property 'doConsumer': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:261 )
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:728)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:380)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:93)
at player.main(MainExecutor.java:117)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy13 implementing java.lang.Runnable,java.io.Serializable,org.spring framework.aop.SpringProxy,org.springframework.aop. framework.Advised] to required type [player.controller.DoStuff] for property 'doConsumer'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy13 implementing java.lang.Runnable,java.io.Serializable,org.spring framework.aop.SpringProxy,org.springframework.aop. framework.Advised] to required type [player.controller.DoStuff] for property 'doConsumer': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.convertForProperty(Abst ractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:472)
... 14 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy13 implementing java.lang.Runnable,java.io.Serializable,org.spring framework.aop.SpringProxy,org.springframework.aop. framework.Advised] to required type [player.controller.DoStuff] for property 'doConsumer': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:386)
... 18 more
Reply With Quote
  #2  
Old Jan 10th, 2009, 03:56 AM
Marten Deinum Marten Deinum is offline
Senior Member
 
Join Date: Jun 2006
Location: The Netherlands
Posts: 9,471
Default

I suggest you read chapter 6 of the reference guide, that explains how spring utilizes AOP. Spring uses a proxy based approach and by default it uses a proxy based approach based on interfaces.

There is a dynamic class created which implements Serializable and Runnable (the 2 interfaces you implements) to the dynamic class is a Runnable and Serializable it is NOT a DoStuff class anymore (as the classcast already suggests).

You have 3 choices
1) Cast to a Runnable instead of a DoStuff (the executor service needs a runnable(
2) Switch to class proxing (chapter 6 explains this)
3) Make DoStuff an interface and your class DoStuffImpl that way DoStuff will be part of the list of interfaces implemented by the dynamic proxy.
__________________
Marten Deinum
  • Senior Java Consultant
  • SpringSource Certified Trainer
Conspect ICT diensten
Blog
LinkedIn
Use the [ code ] tags, young padawan
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:27 PM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.