simple Mybatis + Spring setup - MalformedParameterizedTypeException

1226 views
Skip to first unread message

blackfrancis

unread,
Oct 20, 2010, 5:23:19 PM10/20/10
to mybatis-user
I'm trying to set up Mybatis with Spring as follows:

<beans>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="tms.dataSource" />
</bean>
<bean id="tms.dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost/mydb" />
<property name="username" value="postgres" />
<property name="password" value="postgres" />
</bean>
<bean id="employeeMapper"
class="org.mybatis.spring.MapperFactoryBean">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="mapperInterface"
value="com.mycompany.enterprise.dao.EmployeeMapper" />
</bean>
</beans>

when I load the ApplicationContext, my program throws the following
exception:

Exception in thread "main"
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sqlSessionFactory' defined in class path
resource [applicationContext.xml]: Initialization of bean failed;
nested exception is
java.lang.reflect.MalformedParameterizedTypeException
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:
470)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
$1.run(AbstractAutowireCapableBeanFactory.java:404)
at java.security.AccessController.doPrivileged(Native Method)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:
375)
at org.springframework.beans.factory.support.AbstractBeanFactory
$1.getObject(AbstractBeanFactory.java:263)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:
170)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:
260)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:
184)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:
163)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:
424)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:
729)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:
381)
at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:
139)
at
org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:
83)
at com.tollring.enterprise.Main.main(Main.java:10)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
at
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:
42)
at
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:
35)
at
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:
77)

Can someone please help me work out why?

blackfrancis

unread,
Oct 20, 2010, 9:34:34 PM10/20/10
to mybatis-user
The problem was that I had Spring v2 jars in my classpath instead of
Spring v3.
Reply all
Reply to author
Forward
0 new messages