Problems configuring mybatis-spring in Red5

288 views
Skip to first unread message

Matt

unread,
Sep 9, 2011, 10:28:49 AM9/9/11
to red5in...@googlegroups.com
 

All,

I'm trying to configure MyBatis in an application running under Red5 server. I created an additional spring config filered5-ibatis.xml under WEB-INF which has these beans configured (as described in mybatis-spring user guide):

<bean id="hsqldbDataSource" class="org.apache.commons.dbcp.BasicDataSource"
   
destroy-method="close">
   
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
   
<property name="url" value="jdbc:hsqldb:file:./db/hsqldb/testdb" />
   
<property name="username" value="sa" />
   
<property name="password" value="" />
</bean>

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

<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
   
<property name="mapperInterface" value="test.mappers.UserMapper" />
   
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

When I run the server with the app deployed I get the following exception:

Exception in thread "Launcher:/testapp" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userMapper' defined in ServletContext resource [/WEB-INF/red5-ibatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.mybatis.spring.SqlSessionFactoryBean' to required type 'org.apache.ibatis.session.SqlSessionFactory' for property 'sqlSessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.mybatis.spring.SqlSessionFactoryBean] to required type [org.apache.ibatis.session.SqlSessionFactory] for property 'sqlSessionFactory': no matching editors or conversion strategy found
    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:580)
    at org
.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org
.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org
.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:594)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.mybatis.spring.SqlSessionFactoryBean' to required type 'org.apache.ibatis.session.SqlSessionFactory' for property 'sqlSessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.mybatis.spring.SqlSessionFactoryBean] to required type [org.apache.ibatis.session.SqlSessionFactory] for property 'sqlSessionFactory': no matching editors or conversion strategy found
    at org
.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462)
    at org
.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
    at org
.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
    at org
.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
    at org
.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
    at org
.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org
.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
   
... 9 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.mybatis.spring.SqlSessionFactoryBean] to required type [org.apache.ibatis.session.SqlSessionFactory] for property 'sqlSessionFactory': no matching editors or conversion strategy found
    at org
.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
    at org
.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:447)
   
... 15 more

I'm not sure, but it looks like Spring doesn't see that the SqlSessionFactoryBean implements theFactoryBean interface and so cannot find the way to convert it to SqlSessionFactory. Is this connected with some special configuration or customization of Spring used in Red5? Anyone has any idea how to make this work?

Thanks,

Matt


Hugo Flambó

unread,
Sep 9, 2011, 11:28:42 AM9/9/11
to red5in...@googlegroups.com
I guess problem is not red5.. but your spring beans injection..

Did your application work from outside red5 ? As standalone app (e.g
java main class) .. you can load manually spring bean definitions to
an ApplicationContext object and retrieve your bean... with getbean..
it will solve it's dependencies automatically and probably you will
get the same exception as you are getting inside red5..

hoper that helps..

cheers

Matt

unread,
Sep 10, 2011, 4:46:04 PM9/10/11
to red5in...@googlegroups.com
Hugo,

Thanks for your reply. I tried it and it works fine as a standalone application. I ran a piece of code that loads the red5-ibatis.xml file using FileSystemXmlApplicationContext and it worked fine. I can retrieve the userMapper bean without problems.

So it looks like it's only a problem under Red5. 

M


Matt

unread,
Sep 10, 2011, 6:28:37 PM9/10/11
to red5in...@googlegroups.com
OK, seems like I got it solved. Looks like I had all the Spring jars in my app WEB-INF/lib directory, which probably was bad because they are also in Red5 lib folder, so they were duplicated. After messing with my ivy.xml dependencies configuration and my Eclipse project deployment assembly settings, it started working.

Basically I had to remove standard Libraries/ivy.xml [*] from my project and add two separate ones, which in my case were: ivy.xml [runtime] and ivy.xml [compile]. Then in my Eclipse project settings, "deployment assembly" settings I chose to only deploy the dependecies from ivy.xml [runtime], which didn't contain spring libraries.

M
Reply all
Reply to author
Forward
0 new messages