美文网首页
springboot配置mapper扫描采坑

springboot配置mapper扫描采坑

作者: 李中凯_f395 | 来源:发表于2020-07-03 10:15 被阅读0次

    启动项目报错

    ***************************
    APPLICATION FAILED TO START
    ***************************
    
    Description:
    
    A component required a bean of type 'com.itsm.email.dao.AreaMapper' that could not be found.
    
    
    Action:
    
    Consider defining a bean of type 'com.itsm.email.dao.AreaMapper' in your configuration
    

    目录结构


    image.png

    这句话的意思是找不到这个mapper.xml对应的java类
    解决办法在启动类上加上

    @MapperScan("com.itsm.email.dao")
    

    必须指定到dao这一级目录,连同java类一同扫描进入,否则不会生效
    到此,启动没问题,但是访问时报错

    Invalid bound statement (not found): com.itsm.email.dao.AreaMapper.find
    

    怀疑是mapper文件没有指定,在application.properties中加入

    mybatis.mapper-locations=classpath:com/itsm/email/dao/mapper/*.xml
    

    还不行,推测是不是.xml没扫描进入,看下target文件夹果然没有
    在pom build中加入

            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/**</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
            </resources>
    

    至此访问成功

    相关文章

      网友评论

          本文标题:springboot配置mapper扫描采坑

          本文链接:https://www.haomeiwen.com/subject/llijqktx.html