我知道這個問題已被問了好幾次,但沒有任何答案幫助我。因此我再次問。我讀到當接口類/包名稱不同於映射器xml的類/包時發生此錯誤。我使用相同的類/包名仍然出現此錯誤。mybatis spring應用程序獲取 - org.apache.ibatis.binding.BindingException:無效的綁定語句(未找到):
我使用彈簧的MyBatis並獲得此異常 org.apache.ibatis.binding.BindingException:無效的綁定聲明(未找到):
這裏是我的相關文件: -
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 /類我的兩個接口和xml映射器但問題在於,儘管共享相同的軟件包名稱,但兩次分開ers是用相同的名字創建的。我認爲這兩個應該在生成的類中包含一個包。
以下線可有人請幫助這裏。我從最近2天起就陷入困境。 :( – user911