ssm中Invalid bound statement (not found)错误的处理(IDEA中)

来源:互联网 发布:如何消除身体疲劳知乎 编辑:程序博客网 时间:2024/06/05 17:04

这里写图片描述

根据提示发现if (ms == null) {
throw new BindingException("Invalid bound statement (not found): " + statementName);
}

说明是ms==null导致的,而ms的定义为:MappedStatement ms = null;

也就是没有初始化Statement,如果spring和mybatis配置没问题,那就是mapper.xml和mapper.java没映射成功,
先看一下namespace是否对应,这些都没错的话,那应该就是文件加载的问题
这里写图片描述
src下的.xml没有加进来
解决办法:
1)将.xml放进resources中,同时在spring和mybatis整合文件中加入<property name="mapperLocations" value="classpath:mapper/*.xml"/>,位置如下:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource" />        <property name="mapperLocations" value="classpath:mapper/*.xml"/>    </bean>

2)如果想遵循mapper.xml和mapper.java在同一文件中,而且使用的是maven,可以在maven配置文件中配置(在<build> 标签中加入如下配置):

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

src/main/java这个是资源文件路经,*/.xml要打包的文件类型
注意:第二种方法中不要再加第一种中的配置,否则还是会报错.

阅读全文
0 0
原创粉丝点击