IntelliJ IDEA使用Maven创建Spring和Mybatis工程出现...BindingException: Invalid bound statement (not found)...

使用intelliJ idea创建Mybatis工程后,扫描xml所在的包也配置了,如下,

<!--spring与MyBatis结合,不需要mybatis配置映射文件-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <!--自动扫描mapping.xml-->
        <property name="mapperLocations" value="classpath:com/haoyifen/iot/mappers/*.xml"></property>
    </bean>

但是一直报异常:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

也就是说没有找到有sql语句的xml文件。

找了很久都没找到问题所在,后来去看target文件夹,发现并没有Mybatis的xml文件。原来是Maven默认并不打包源码目录下的xml文件,在pom.xml中添加如下的配置,将resource下的所有文件(spring和jdbc的配置也放进来)和源代码目录下的所有xml文件(Mybatis的xml映射文件)都打包进目标文件中。

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

再次运行就可以了

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
发布了44 篇原创文章 · 获赞 37 · 访问量 22万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章