Invalid bound statement (not found)错误

本文详细介绍了在Spring Boot项目中遇到的MyBatis Plus XML映射文件未能正确加载的问题及解决方案。作者分享了如何在Maven的pom.xml中配置资源文件,以确保XML映射文件能够被编译并包含在内。同时,文章还提供了在配置类中指定映射文件位置的方法,以避免启动时报错。

都对着,为什么会报这个错呢,mapper也拿到了,为什么查询时出错呢,最后看target里编译的文件发现少了mapping,xml没编译过去。


 

我的目录结构:dao层都编译过去了,但mapper.xml没有,那就是编译没包含进去

    

解决方法:pom文件里加上就好了。(然而并没有)

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

 


 

    好高兴的看到target里有了xml文件,但是启动还是报错了,Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:com/wskt/module/*/dao/mapping/**Mapper.xml]

原因:

  

这样一个流程调下去,路径没有得到解析,所以找不到,
如果在配置类里就可以:
 @Bean
    @ConfigurationProperties(prefix = "mybatis-plus")
    public SqlSessionFactoryBean sqlSessionFactory() throws IOException {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("com/wskt/module/*/dao/mapping/**Mapper.xml"));
        sqlSessionFactoryBean.setDataSource(dynamicDataSource());
        return sqlSessionFactoryBean;
    }

原因找到了,就看怎么指定PathMatchingResourcePatternResolver

 

转载于:https://www.cnblogs.com/javage/p/10691986.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值