MyBatis and Spring: database connection

316 views
Skip to first unread message

Vladislav Krejcirik

unread,
Nov 16, 2010, 7:13:26 AM11/16/10
to mybatis-user
Hi, I use Mybatis and Spring framework. I defined beans according to
Mybatis wiki page, like this:

<bean id="dataSource"
class="org.apache.ibatis.datasource.pooled.PooledDataSource"
destroy-method="close">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:file:~/clan-cr" />
<property name="username" value="admin" />
<property name="password" value="admin" />
</bean>

<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="coreMapper" class="org.mybatis.spring.MapperFactoryBean">
<property name="mapperInterface"
value="com.pikeelectronic.clan.core.CoreMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>


When I deploy app on Tomcat server, I get this exception:

[ERROR] ContextLoader - Context initialization failed
<org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'sqlSessionFactory' defined in class path resource
[com/pikeelectronic/clan/core/srv/services-prd.xml]: Initialization of
bean failed; nested exception is
java.lang.reflect.MalformedParameterizedTypeException>org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlSessionFactory' defined in class path
resource [com/pikeelectronic/clan/core/srv/services-prd.xml]:
Initialization of bean failed; nested exception is
java.lang.reflect.MalformedParameterizedTypeException
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
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:222)
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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at
com.pikeelectronic.clan.core.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4323)
at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4780)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at
org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at
org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:771)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at
org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:988)
at
org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:275)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at
org.apache.catalina.core.StandardService.startInternal(StandardService.java:427)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at
org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:649)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
at org.apache.catalina.startup.Catalina.start(Catalina.java:585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
at
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(Unknown
Source)
at
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(Unknown
Source)
at
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(Unknown Source)
at
sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(Unknown
Source)
at
sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Unknown Source)
at sun.reflect.generics.tree.ClassTypeSignature.accept(Unknown Source)
at
sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(Unknown
Source)
at java.lang.Class.getGenericInterfaces(Unknown Source)
at
org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:151)
at
org.springframework.core.GenericTypeResolver.resolveParameterType(GenericTypeResolver.java:81)
at
org.springframework.beans.GenericTypeAwarePropertyDescriptor.getWriteMethodParameter(GenericTypeAwarePropertyDescriptor.java:109)
at
org.springframework.beans.GenericTypeAwarePropertyDescriptor.getPropertyType(GenericTypeAwarePropertyDescriptor.java:91)
at
org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at
org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 35 more

Thanks.

--
/**************************************/
Best regards / S pozdravem
Vladislav Krej�i��k

http://www.vkrejcirik.info

Eduardo

unread,
Nov 16, 2010, 12:41:10 PM11/16/10
to mybatis-user
Hi

You should contact blackfrancis because had exactly the same error as
you and solved it.
http://groups.google.com/group/mybatis-user/browse_thread/thread/42698cff74504603
Reply all
Reply to author
Forward
0 new messages