我知道这个问题已经被问过好几次了,但没有一个答案对我有帮助。因此我又问了一遍。我读到当接口类/包名称与映射器 xml 的类/包不同时会发生此错误。我使用相同的类/包名称仍然出现此错误。
我正在使用 spring-mybatis 并收到此异常 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
这是我的相关文件:-
1)EmployeMapper.java(接口)
com.XXX.org.mapper
public interface EmployeeMapper {
public Employee getEmployeeFullDetails(String employeeId);
}
2) com.XXX.org.mapper.EmployeeMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.XXX.org.mapper.EmployeeMapper">
<select id="getEmployeeFullDetails" parameterType="String" resultType="com.XXX.org.Domain.Employee">
SELECT * from employee emp
where emp.employeeId = #{employeeId}
</select>
</mapper>
3)ApplicationContext.xml
<context:annotation-config/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" >
<property name="driverClassName" value="${dataSource.driverClassName}" />
<property name="username" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />
<property name="url" value="${dataSource.url}" />
</bean>
<context:component-scan base-package="com.XXX.org"/>
<context:annotation-config/>
<tx:annotation-driven />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.XXX.org.domain" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name="basePackage" value="com.XXX.org.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
4)DBUnit测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:service-bean.xml"})
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class})
public class EmployeeTest {
@Autowired
EmployeeMapper employeeMapper;
@Test
@DatabaseSetup(value = {"/employee.xml"} , type= com.github.springtestdbunit.annotation.DatabaseOperation.CLEAN_INSERT)
public void testInsertEmployee() {
Employee employee= employeeMapper.getEmployeeFullDetails("testUser");
}
我可以在 WEBINF/classes 中看到我的界面和 xml 映射器,但问题是尽管共享相同的包名称,但创建了两个具有相同名称的单独文件夹。我认为两者都应该在生成的类中的一个包中。