开发者社区> 问答> 正文

在mybatis和spring整合中使用spring的MapperScanner?400报错

在mybatis和spring整合中使用spring的MapperScannerConfigurer 运行出错? 400 报错 DEBUG [main] - Initializing new StandardEnvironment
DEBUG [main] - Adding [systemProperties] PropertySource with lowest search precedence
DEBUG [main] - Adding [systemEnvironment] PropertySource with lowest search precedence
DEBUG [main] - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
DEBUG [main] - Looking for matching resources in directory tree [E:\myworkspace\mybatis_spring3\bin\com\nemo\ssm\mapper]
DEBUG [main] - Searching directory [E:\myworkspace\mybatis_spring3\bin\com\nemo\ssm\mapper] for files matching pattern [E:/myworkspace/mybatis_spring3/bin/com/nemo/ssm/mapper/**/*.class]
DEBUG [main] - Resolved location pattern [classpath*:com/nemo/ssm/mapper/**/*.class] to resources [file [E:\myworkspace\mybatis_spring3\bin\com\nemo\ssm\mapper\UserMapper.class], file [E:\myworkspace\mybatis_spring3\bin\com\nemo\ssm\mapper\UserMapperTest.class]]
 INFO [main] - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@71318ec4: defining beans [org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,dataSource,sqlSessionFactory,org.mybatis.spring.mapper.MapperScannerConfigurer#0]; root of factory hierarchy


展开
收起
爱吃鱼的程序员 2020-06-04 16:28:52 757 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    spring和mybatis整合,需要添加mybatis-spring,需要使用spring来启动添加的插件来初始化mybatis,然后在spring里面注入######@阿信sxq 用你的代码试了,但xml文件会提示The prefix "mybatis" for element "mybatis:scan" is not bound. 怎么解决啊?######回复 @渊兮 : ssm 架构参考 http://git.oschina.net/juapk/SpringWind######整合包我已经添了。如果使用使用MapperFactoryBean的话 不报错。用批量扫描MapperScannerConfigurer的话就会报这一错误。实在想不明白。搜了很多也没找到正确的答案。。。######

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml" /> <property name="mapperLocations" value="classpath:mapper/*.xml" /> </bean> <!-- 自动加载dao --> <mybatis:scan base-package="com.xxxxxx.dao" />



    ######
    <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:tx="http://www.springframework.org/schema/tx" 
        xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-4.2.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
            http://mybatis.org/schema/mybatis-spring
            http://mybatis.org/schema/mybatis-spring.xsd">



    ######这是我的spring的applicationContext.xml 的配置文件 你看看有什么不对的######<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
    <!-- 加载配置文件 -->
    <context:property-placeholder location="classpath:db.properties"/>
    <!-- 数据库连接池 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
           <property name="driverClassName" value="${jdbc.driver}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="maxActive" value="10"/>
    <property name="maxIdle" value="5"/>
    </bean>
    <!-- mapper配置 -->
    <!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 数据库连接池 -->
    <property name="dataSource" ref="dataSource" />
    <!-- 加载mybatis的全局配置文件 -->
    <property name="configLocation" value="classpath:mybatis/mybatis_config.xml" />
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
      <property name="basePackage" value="com.nemo.ssm.mapper"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>
    </beans>
    ######楼主你好,请问你的问题解决了吗?我也碰到了一样的问题###### 研究了半天终于解决了,jre版本换成1.7的就行了,mybatis-spring-1.2.2插件和jre1.8运行环境不兼容######开发请用jdk···不然后后面还会有问题
    2020-06-04 17:49:08
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多