SSM整合框架出现Mapper扫描问题
下面展示一些 Invalid bound statement (not found)
。
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.kevin.dao.SmbmsUserDao.countUser
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
//等等不做说明
这种问题就是Mapper没有被扫描导致的。
解决办法:
1.检查Mybatis配置文件是否进行配置
Mybatis配置文件 Mybatis.xml
。
<mappers>
<!--name:是包名, 这个包中的所有mapper.xml一次都能加载-->
<package name="com.kevin.dao"/>
</mappers>
2.检查Spring配置文件ApplicationContext.xml
Spring配置文件 ApplicationContext.xml
。
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis.xml"/>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
3.检查Pom.xml文件是否含有resource
<build>
<resources>
<resource>
<directory>src/main/java</directory><!--所在的目录-->
<includes><!--包括目录下的.properties,.xml 文件都会扫描到-->
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
基本上就可以解决