在mybatis和spring整合中使用spring的MapperScannerConfigurer 运行出错

渊兮 发布于 2016/05/19 15:42
阅读 1K+
收藏 0
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

加载中
0
阿信sxq
阿信sxq
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的话就会报这一错误。实在想不明白。搜了很多也没找到正确的答案。。。
0
阿信sxq
阿信sxq
<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" />



0
阿信sxq
阿信sxq
<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 的配置文件 你看看有什么不对的
0
渊兮
渊兮
<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>
0
s
secretband
楼主你好,请问你的问题解决了吗?我也碰到了一样的问题
0
s
secretband
研究了半天终于解决了,jre版本换成1.7的就行了,mybatis-spring-1.2.2插件和jre1.8运行环境不兼容
skhuhu
skhuhu
开发请用jdk···不然后后面还会有问题
返回顶部
顶部