2011-10-27 106 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