Martin Becker
Martin Becker

Reputation: 3421

Spring 3 and MyBatis 3.0.4 / 3.0.6: MalformedParameterizedTypeException

I am trying to use Spring 3.0.5.RELEASE together with MyBatis in a Maven environment. I added the mybatis-spring dependency. This turned out not to work due to a MalformedParameterizedTypeException (a detailed stacktrace is included below).

Stacktrace:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:53)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:104)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.visitor.Reifier.visitArrayTypeSignature(Reifier.java:159)
    at sun.reflect.generics.tree.ArrayTypeSignature.accept(ArrayTypeSignature.java:42)
    at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94)
    at java.lang.reflect.Method.getGenericParameterTypes(Method.java:300)
    at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:385)
    at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116)
    at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:74)
    at java.beans.MethodDescriptor.<init>(MethodDescriptor.java:58)
    at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1196)
    at java.beans.Introspector.getBeanInfo(Introspector.java:423)
    at java.beans.Introspector.getBeanInfo(Introspector.java:189)
    at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:224)
    at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:149)
    at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:305)
    at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptorInternal(BeanWrapperImpl.java:335)
    at org.springframework.beans.BeanWrapperImpl.isWritableProperty(BeanWrapperImpl.java:407)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    ... 19 more

Upvotes: 3

Views: 4531

Answers (1)

Martin Becker
Martin Becker

Reputation: 3421

There are quite some posts concerning this iusse, yet most of them refer to the problem as being caused by having some Spring 2 dependency somewhere in the class-path which was not the case for me:

The first link mentions an imcompatability to Spring 2 because of the BeanFactory being paramterized in Spring 3 but not in Spring 2. Well, it turns out that the real problem was, that I had a separate MyBatis version (3.0.4) in my dependencies. I changed version 3.0.4 to version 3.0.6 and everything worked just fine. Usually, if one does not have a separate MyBatis dependency somewhere in the project (or parent projects!), the mybatis-spring artifact from Maven comes with MyBatis 3.0.6.

Side note: I had some other issues with the Maven dependency management system I was using because the changed pom.xml dependency would not propagate through to the top-level projects. Obviously after running a mvn clean install -Dmaven.text.skip=true dependencies got propagated to the top level projects and everything was working.

Upvotes: 2

Related Questions