Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.jou.mapper.PhoneMapper.findAll
spring+mybatis+Maven整合时遇到的问题
解决方法
1、mapper的java和xml都在src/main/java下
在pom里加上这段配置
<build>
<!-- 资源目录 -->
<resources>
<resource>
<!-- 设定主资源目录 -->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>**/*.yaml</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
</build>
报错原因:maven在打包时,默认不打包src/main/java下的xml文件
2、mapper的xml在src/main/resources下
在spring核心配置文件里配置session工厂处加上这句
<property name="mapperLocations" value="classpath:com.jou.mapper/*.xml"></property>
添加位置
<!--配置sessionFactory-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:sqlMapperConfig.xml" ></property>
<!--配置xml路劲,根据namespace找到class-->
<property name="mapperLocations" value="classpath:com.jou.mapper/*.xml"></property>
</bean>
报错原因:不在同一个包下,需要先找到xml,再根据namespace找到对应的class