薯片加可乐 2017-05-18 16:11 采纳率: 0%
浏览 4093

在spring中使用MapperScannerConfigurer无法扫描到我定义的接口?

spring.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置整合mybatis过程 -->
<!-- 1.配置数据库相关参数properties的属性:${url} -->

<!-- 2.数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <!-- 配置连接池属性 -->
    <property name="driverClass" value="${jdbc.driver}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />

    <!-- c3p0连接池的私有属性 -->
    <property name="maxPoolSize" value="30" />
    <property name="minPoolSize" value="10" />
    <!-- 关闭连接后不自动commit -->
    <property name="autoCommitOnClose" value="false" />
    <!-- 获取连接超时时间 -->
    <property name="checkoutTimeout" value="10000" />
    <!-- 当获取连接失败重试次数 -->
    <property name="acquireRetryAttempts" value="2" />
</bean>

<!-- 3.配置SqlSessionFactory对象 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 注入数据库连接池 -->
    <property name="dataSource" ref="dataSource" />
    <!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    <!-- 扫描entity包 使用别名 -->
    <property name="typeAliasesPackage" value="entity" />
    <!-- 扫描sql配置文件:mapper需要的xml文件 -->
    <property name="mapperLocations" value="classpath:Mapper/*.xml" />
</bean>

<!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 注入sqlSessionFactory -->
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    <!-- 给出需要扫描Dao接口包 -->
    <property name="basePackage" value="dao" />
</bean>

报错信息:
五月 19, 2017 12:07:08 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5cb0d902: startup date [Fri May 19 00:07:08 CST 2017]; root of context hierarchy
五月 19, 2017 12:07:09 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring.xml]
五月 19, 2017 12:07:09 上午 org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
信息: Loading properties file from class path resource [jdbc.properties]
五月 19, 2017 12:07:09 上午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
五月 19, 2017 12:07:10 上午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
00:07:10.501 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
00:07:10.734 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Class not found: org.jboss.vfs.VFS
00:07:10.734 [main] DEBUG org.apache.ibatis.io.ResolverUtil - JBoss 6 VFS API is not available in this environment.
00:07:10.742 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Class not found: org.jboss.vfs.VirtualFile
00:07:10.743 [main] DEBUG org.apache.ibatis.io.ResolverUtil - VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.
00:07:10.744 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Using VFS adapter org.apache.ibatis.io.DefaultVFS
00:07:10.750 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Find JAR URL: file:/home/andy/%e6%a1%8c%e9%9d%a2/project/wendang/target/classes/entity
00:07:10.751 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Not a JAR: file:/home/andy/%e6%a1%8c%e9%9d%a2/project/wendang/target/classes/entity
00:07:10.973 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Reader entry: Book.class
00:07:10.974 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Listing file:/home/andy/%e6%a1%8c%e9%9d%a2/project/wendang/target/classes/entity
00:07:10.974 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Find JAR URL: file:/home/andy/%e6%a1%8c%e9%9d%a2/project/wendang/target/classes/entity/Book.class
00:07:10.975 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Not a JAR: file:/home/andy/%e6%a1%8c%e9%9d%a2/project/wendang/target/classes/entity/Book.class
00:07:10.981 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Reader entry: ���� 4 A
00:07:10.982 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class entity.Book matches criteria [is assignable to Object]
00:07:10.989 [main] DEBUG o.m.spring.SqlSessionFactoryBean - Scanned package: 'entity' for aliases
00:07:11.149 [main] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed configuration file: 'class path resource [mybatis-config.xml]'
00:07:11.277 [main] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed mapper file: 'file [/home/andy/桌面/project/wendang/target/classes/Mapper/BookDao.xml]'
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'BookDao' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at TestMybatis.main(TestMybatis.java:11)

Process finished with exit code 1

  • 写回答

1条回答 默认 最新

  • 半杯凉月 2017-05-19 01:16
    关注

    你的basePackage配置的全路径对么

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?