Problèmes de configuration mybatis-printemps Red5
Question
Tous,
Je suis en train de configurer mybatis dans une application en cours d'exécution sous serveur Red5. Je créé un red5-ibatis.xml
supplémentaire du fichier de configuration de ressort sous WEB-INF
qui possède ces grains configurés (comme décrit dans le mode d'emploi mybatis-ressort):
<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>
Quand je lance le serveur avec l'application déployée je reçois l'exception suivante:
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
Je ne sais pas, mais il semble que Spring ne voit pas que la SqlSessionFactoryBean
implémente l'interface FactoryBean
et ne peut donc pas trouver le moyen de le convertir en SqlSessionFactory
?
Quoi qu'il en soit, des idées comment résoudre ce problème?
La solution
OK, semble que je l'ai résolu. On dirait que j'avais tous les pots de printemps dans mon répertoire app WEB-INF/lib
, ce qui a probablement été mauvais parce qu'ils sont également dans le dossier de Red5 lib
, donc ils ont été dupliqués. Après déconner avec ma configuration des dépendances de ivy.xml
et mes paramètres d'assemblage de déploiement de projet Eclipse, il a commencé à travailler.
En fait, je devais retirer Libraries/ivy.xml [*]
la norme de mon projet Eclipse et ajouter deux séparés, ceux qui dans mon cas étaient: ivy.xml [runtime]
et ivy.xml [compile]
. Puis, dans mes propriétés de projet Eclipse, dans les paramètres « assemblage déploiement » j'ai choisi de ne déployer les dependecies de ivy.xml [runtime]
, qui ne contenait pas les bibliothèques de printemps.
Pas plus d'exceptions.