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


 

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

    Invalid bound statement (not found)错误

解决方法: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]

原因:

  

Invalid bound statement (not found)错误

这样一个流程调下去,路径没有得到解析,所以找不到,
如果在配置类里就可以:
 @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

 

相关文章:

  • 2021-09-28
  • 2021-05-23
  • 2021-08-02
  • 2021-10-19
  • 2021-08-29
  • 2022-01-09
  • 2021-11-24
  • 2022-01-12
猜你喜欢
  • 2021-04-15
  • 2021-05-17
  • 2021-06-18
  • 2022-12-23
  • 2021-09-16
  • 2021-09-08
相关资源
相似解决方案