• Invalid bound statement (not found)错误


    都对着,为什么会报这个错呢,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

    ...
  • 相关阅读:
    C# 静态类和非静态类的区别
    C# 集合
    C#字符串
    C# 虚方法 抽象方法 接口
    C#常用的关键字
    扫描功能小结 (扫描二维码、条形码)
    QQ空间/朋友圈类界面的搭建
    tableview左滑按钮 tableviewcell自定义左滑按钮
    UITextView 开始编辑时,文字没有左上角对齐解决办法 tableview整体上移
    图片、视频上传小记(基于七牛云)
  • 原文地址:https://www.cnblogs.com/javage/p/10691986.html
Copyright © 2020-2023  润新知