开发者社区> 问答> 正文

mybatis配置通用mapper报错,请大侠们帮帮忙,谢谢 403.10 禁止访问:配置无效 

我只这样配置的,如下:

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

展开
收起
kun坤 2020-05-27 14:01:40 573 0
1 条回答
写回答
取消 提交回答
  • 推荐使用  Mybatis-Plus 启动加载 XML 配置时注入单表 SQL 操作 ,启动注入非拦截实现、使用简单,性能更优。 ######你好,mybatis-plus是个工具的集合包吧?不是一个具体的工具吧?######谢谢######看起来是配置有问题,你时参照官方示例来做的吗######回复 @marshalbin : 参照官方样列,很容易的啊,给出你的代码######是的,就是配置完了有问题,请问您有这方面的经验吗?能否指导一下?###### 关于mybatis和spring的详细配置,可关注:http://git.oschina.net/wangkang/llsfw
    希望能够帮到你. ###### Caused by: java.lang.IllegalStateException: Cannot convert value of type [tk.mybatis.spring.mapper.MapperScannerConfigurer] to required type 
    查查这两句吧,没见过类似的错误,你用mybatis的拦截器了? ######

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

    看起来是配置有问题,你时参照官方示例来做的吗
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->  

        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  

            <property name="basePackage" value="com.IDao" />  

            <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  

        </bean>  
    上面是代码,请看看有问题吗? ######这样看看不出来问题啊######

    <value> mappers=tk.mybatis.mapper.common.Mapper

       </value></pre> 修改为 
    
    <value>
            tk.mybatis.mapper.common.Mapper
            
           </value>
    2020-05-27 14:53:59
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载