您的位置:首页 > 编程语言 > Java开发

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

2016-04-16 20:36 716 查看
使用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>


再次运行就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: