全部,

我正在尝试在Red5服务器下运行的应用程序中配置MyBatis。我创建了一个额外的春季配置文件 red5-ibatis.xml 在下面 WEB-INF 配置了这些豆(如Mybatis-Spring用户指南中所述):

<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

我不确定,但是看起来春天没有看到 SqlSessionFactoryBean 实现 FactoryBean 接口,因此找不到将其转换为 SqlSessionFactory?

无论如何,有什么想法如何解决?

有帮助吗?

解决方案

好的,似乎我解决了。看起来我的应用中都有所有弹簧罐 WEB-INF/lib 目录,这可能很糟糕,因为它们也在red5中 lib 文件夹,所以它们被复制了。弄乱我的 ivy.xml 依赖项配置和我的Eclipse项目部署程序集设置,它开始工作。

基本上我必须删除标准 Libraries/ivy.xml [*] 从我的日食项目中添加两个单独的项目,在我的情况下是: ivy.xml [runtime]ivy.xml [compile]. 。然后在我的日食项目属性中,在“部署组件”设置中,我选择仅部署这些依赖项 ivy.xml [runtime], ,不包含春季库。

没有更多例外。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top