mybatis配置通用mapper报错,请大侠们帮帮忙,谢谢?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

mybatis配置通用mapper报错,请大侠们帮帮忙,谢谢?报错

爱吃鱼的程序员 2020-06-09 16:22:59 30

我只这样配置的,如下:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <!-- 自动扫描mapping.xml文件 -->  
        <property name="mapperLocations" value="classpath:com/mapping/*.xml"></property>  
        <property name="plugins">
        <array>
        <!-- 配置数据库分页的插件PageHelper -->
        <bean class="com.github.pagehelper.PageHelper">
        <property name="properties">
        <value>dialect=mysql</value>
        </property>
        </bean>
        
        <!-- 配置通用Mapper,实现单表增删查改,当表结构变动时无需重新生成配置类和文件 -->
        <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.IDao"/>
   <property name="properties">
       <value>
        mappers=tk.mybatis.mapper.common.Mapper
        
       </value>
   </property>
</bean>
        </array>
        </property>
    </bean>  
但是如下错,请大侠帮忙指导一下:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'midUserMapper' defined in file [E:\tools-acting\eclipse4.3.1\workspace\zbx.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\springmvcmybatis\WEB-INF\classes\com\IDao\MidUserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [E:\tools-acting\eclipse4.3.1\workspace\zbx.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\springmvcmybatis\WEB-INF\classes\spring\spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.Object[]] to required type [org.apache.ibatis.plugin.Interceptor[]] for property 'plugins'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [tk.mybatis.spring.mapper.MapperScannerConfigurer] to required type [org.apache.ibatis.plugin.Interceptor] for property 'plugins[1]': no matching editors or conversion strategy found
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
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:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'midUserMapper' defined in file [E:\tools-acting\eclipse4.3.1\workspace\zbx.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\springmvcmybatis\WEB-INF\classes\com\IDao\MidUserMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [E:\tools-acting\eclipse4.3.1\workspace\zbx.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\springmvcmybatis\WEB-INF\classes\spring\spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.Object[]] to required type [org.apache.ibatis.plugin.Interceptor[]] for property 'plugins'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [tk.mybatis.spring.mapper.MapperScannerConfigurer] to required type [org.apache.ibatis.plugin.Interceptor] for property 'plugins[1]': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:512)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:486)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:615)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [E:\tools-acting\eclipse4.3.1\workspace\zbx.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\springmvcmybatis\WEB-INF\classes\spring\spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.Object[]] to required type [org.apache.ibatis.plugin.Interceptor[]] for property 'plugins'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [tk.mybatis.spring.mapper.MapperScannerConfigurer] to required type [org.apache.ibatis.plugin.Interceptor] for property 'plugins[1]': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 43 more
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.lang.Object[]] to required type [org.apache.ibatis.plugin.Interceptor[]] for property 'plugins'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [tk.mybatis.spring.mapper.MapperScannerConfigurer] to required type [org.apache.ibatis.plugin.Interceptor] for property 'plugins[1]': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:591)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
... 49 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [tk.mybatis.spring.mapper.MapperScannerConfigurer] to required type [org.apache.ibatis.plugin.Interceptor] for property 'plugins[1]': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:302)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:143)
at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:490)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:212)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)

Java 数据库连接 数据库 Spring mybatis
分享到
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-09 16:23:17
    推荐使用 Mybatis-Plus  启动加载XML配置时注入单表SQL操作,启动注入非拦截实现、使用简单,性能更优。 你好,mybatis-plus是个工具的集合包吧?不是一个具体的工具吧?谢谢看起来是配置有问题,你时参照官方示例来做的吗回复 @marshalbin:参照官方样列,很容易的啊,给出你的代码是的,就是配置完了有问题,请问您有这方面的经验吗?能否指导一下?

    关于mybatis和spring的详细配置,可关注:http://git.oschina.net/wangkang/llsfw

    希望能够帮到你.

    Causedby:java.lang.IllegalStateException:Cannotconvertvalueoftype[tk.mybatis.spring.mapper.MapperScannerConfigurer]torequiredtype 

    查查这两句吧,没见过类似的错误,你用mybatis的拦截器了?

    引用来自“阿信sxq”的评论

    看起来是配置有问题,你时参照官方示例来做的吗这样看看不出来问题啊

    <value>mappers=tk.mybatis.mapper.common.Mapper</value>修改为

    <value>tk.mybatis.mapper.common.Mapper</value>







    0 0
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题
推荐课程