2011-09-05 106 views
0

全部,在Red5中配置mybatis-spring的問題

我想在運行Red5服務器的應用程序中配置MyBatis。我創建了一個附加的彈簧配置文件red5-ibatis.xmlWEB-INF下具有這些豆配置(如在MyBatis的彈簧的用戶指南中所述):

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

當我運行與應用程序部署我得到下面的異常的服務器:

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 

我不知道,但它看起來像Spring沒有看到SqlSessionFactoryBean實現FactoryBean接口等無法找到將其轉換爲SqlSessionFactory的方式嗎?

無論如何,任何想法如何解決它?

回答

0

好的,好像我解決了它。看起來我在我的應用程序WEB-INF/lib目錄中有所有的Spring jar,這可能是不好的,因爲它們也在Red5 lib文件夾中,所以它們被複制。在解決了我的ivy.xml依賴項配置和我的Eclipse項目部署程序集設置後,它開始工作。

基本上我不得不從我的Eclipse項目中刪除標準Libraries/ivy.xml [*]並添加兩個單獨的,在我的情況下是:ivy.xml [runtime]ivy.xml [compile]。然後在我的Eclipse項目屬性中,在「部署程序集」設置中,我選擇僅部署來自ivy.xml [runtime]的不包含Spring庫的依賴項。

沒有更多的例外。