Announcement Announcement Module
Collapse
No announcement yet.
Generic type not support when determining expected type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generic type not support when determining expected type

    Hello,
    I have encountered some problem using generic types. When the context is loaded, this error occurs:
    Code:
    ...
    ...
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#7': Cannot resolve reference to bean 'org.springframework.integration.handler.ServiceActivatingHandler#4' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.ServiceActivatingHandler#4': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.handler.ServiceActivatingHandler]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Failed to determine expected type for parameter [T] on Method [public es.dtg.nm.process.message.content.result.IResultContent es.dtg.nm.process.handler.result.AbstractResultHandler.handle(es.dtg.nm.process.message.content.result.IResultContent)]
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:479)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:682)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:614)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:450)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:223)
    	at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:652)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:610)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412)
    	... 189 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.ServiceActivatingHandler#4': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.handler.ServiceActivatingHandler]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Failed to determine expected type for parameter [T] on Method [public es.dtg.nm.process.message.content.result.IResultContent es.dtg.nm.process.handler.result.AbstractResultHandler.handle(es.dtg.nm.process.message.content.result.IResultContent)]
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    	... 202 more
    Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.handler.ServiceActivatingHandler]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Failed to determine expected type for parameter [T] on Method [public es.dtg.nm.process.message.content.result.IResultContent es.dtg.nm.process.handler.result.AbstractResultHandler.handle(es.dtg.nm.process.message.content.result.IResultContent)]
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)
    	... 214 more
    Caused by: java.lang.IllegalArgumentException: Failed to determine expected type for parameter [T] on Method [public es.dtg.nm.process.message.content.result.IResultContent es.dtg.nm.process.handler.result.AbstractResultHandler.handle(es.dtg.nm.process.message.content.result.IResultContent)]
    	at org.springframework.util.Assert.notNull(Assert.java:112)
    	at org.springframework.integration.handler.PayloadTypeMatchingHandlerMethodResolver.determineExpectedType(PayloadTypeMatchingHandlerMethodResolver.java:110)
    	at org.springframework.integration.handler.PayloadTypeMatchingHandlerMethodResolver.initMethodMap(PayloadTypeMatchingHandlerMethodResolver.java:68)
    	at org.springframework.integration.handler.PayloadTypeMatchingHandlerMethodResolver.<init>(PayloadTypeMatchingHandlerMethodResolver.java:47)
    	at org.springframework.integration.handler.MessageMappingMethodInvoker.createResolverForMethodName(MessageMappingMethodInvoker.java:180)
    	at org.springframework.integration.handler.MessageMappingMethodInvoker.<init>(MessageMappingMethodInvoker.java:85)
    	at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:42)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
    	... 216 more
    I saw that the generic type (T in the example) is not supported in the method determineExpectedType of spring-integration class PayloadTypeMatchingHandlerMethodResolver. There are only 2 validations for types: ParameterizedType and Class.
    My class:
    Code:
    public abstract class AbstractResultHandler<T extends IResultContent> implements IGenericHandler<T>{
    
    	public IResultContent handle(T result) {
    		try{
    			IResultContent newResult = doHandle(result);
    			if(newResult == null){
    				return null;
    			}else{
    				return newResult;
    			}
    		}catch(Exception e){
    			throw new ResultHandlingException(result, "Failed to handle result", e);
    		}
    	}
    
    	protected abstract IResultContent doHandle(T result);
    	
    }
    Is it some restriction. If not, is it posible to allow "Type" type?

    Thanks,

  • #2
    Hi,

    Thanks for pointing this out.
    I created http://jira.springframework.org/browse/INT-559, so please follow up on that. Please comment on it or add any information you would find helpful.

    Marius

    Comment

    Working...
    X