2011-10-27 31 views
3

我正在试图在Spring环境中使用Spring 3.0.5.RELEASE以及MyBatis。我添加了mybatis-spring依赖项。事实证明,由于MalformedParameterizedTypeException(下面包含详细的堆栈跟踪)而不起作用。Spring 3和MyBatis 3.0.4/3.0.6:MalformedParameterizedTypeException

堆栈跟踪:

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 
+1

海事组织这应该被改写为你回答和接受的问题。 –

+0

有道理。谢谢。 –

回答

2

有关于这个iusse颇有些职位,但他们大部分指的是问题,因为在这是不是这样的类路径的某处有一些弹簧2依赖所引起对我来说:

第一个链接提到了Spring 2的不兼容性,因为在Spring 3中BeanFactory被参数化,但在Spring 2中没有。事实证明真正的问题是,我有一个单独的MyBatis版本(3.0.4 )在我的依赖。我改变了版本3.0.4到版本3.0.6和一切工作得很好。通常,如果某个项目(或父项目!)中没有单独的MyBatis依赖项,则来自Maven的mybatis-spring工件随附MyBatis 3.0.6

附注:我在使用Maven依赖项管理系统时遇到了一些其他问题,因为更改后的pom.xml依赖项不会传播到顶层项目。显然,在运行mvn clean install之后,-Dmaven.text.skip = true依赖关系被传播到顶级项目,并且一切正常。

+0

有相同的问题:通过首先删除单独的mybatis依赖关系,然后删除一些2.X弹簧依赖关系解决。 – sibidiba