Invalid bound statement (not found)錯誤

都對着,爲何會報這個錯呢,mapper也拿到了,爲何查詢時出錯呢,最後看target裏編譯的文件發現少了mapping,xml沒編譯過去。java


 

個人目錄結構:dao層都編譯過去了,但mapper.xml沒有,那就是編譯沒包含進去spring

    

解決方法:pom文件里加上就行了。(然而並無)sql

<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]mybatis

緣由:app

  

這樣一個流程調下去,路徑沒有獲得解析,因此找不到,
若是在配置類裏就能夠:
 @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;
    }

緣由找到了,就看怎麼指定PathMatchingResourcePatternResolvermaven

相關文章
相關標籤/搜索