我得到的类没有发现异常反复。
Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error registering typeAlias for 'Emp'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath*:com.attinad.model.Employee下面给出了我的myBati-config.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases><typeAlias type="classpath*:com.attinad.model.Employee" alias="Emp"/></typeAliases>
<mappers>
<mapper resource="classpath:com/attinad/mappers/EmployeeMapper.xml" />
</mappers>
</configuration>和ds-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans >
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/corpds"/>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="classpath*:com/attinad/model/*"/>
<property name="configLocation" value="classpath:myBatis-config.xml" />
<property name="mapperLocations" value="classpath*:com/attinad/mappers/*.xml" />
</bean>
</beans>我的映射文件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.attinad.dao.EmployeeMapperInterface">
<resultMap type="Emp" id="EmpResult">
<id property="id" column="id"/>
<result property="createdAt" column="createdAt"/>
<result property="department" column="department"/>
<result property="displayName" column="displayName"/>
<result property="emailId" column="emailId"/>
<result property="isEnable" column="isEnable"/>
<result property="name" column="name"/>
<result property="updatedAt" column="updatedAt"/>
</resultMap>
<select id="getEmployeeWithId" parameterType="Long" resultMap="EmpResult">
select * from
employees where
id=#{empId}
</select>
</mapper>这是我的刀课:
package com.attinad.dao;
import java.util.*;
import com.attinad.model.*;
public interface EmployeeMapperInterface extends BaseMapperInterface{
public List<Employee> getEmployeeWithId(long id);
public int insertEmployee(Employee e);
public int updateEmployee(Employee e);
public void deleteEmployee(int id);
}我的服务班:
package com.attinad.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.attinad.dao.EmployeeMapperInterface;
import com.attinad.model.Employee;
@Service
public class EmployeeService implements EmployeeBaseService{
@Autowired
EmployeeMapperInterface employeeMapper;
@Override
public Employee getEmployeeById(long empId){
List<Employee> empList = employeeMapper.getEmployeeWithId(empId);
if(empList != null && empList.size()>0){
//System.out.println("List accumulated");
System.out.println(empList);
return (Employee) empList.get(0);
}
return null;
}
}Eclipse构建路径:src/main/ Java包含在Java构建路径中,我的包在这个类路径下。
请帮我解决这个错误。我不知道真正的原因。当我移除resultMap并使它成为ResultType="hashMap“时,它就起作用了。但是现在,如果我尝试这样做,我将为其他类获得ClassNotFound。
发布于 2014-06-18 05:01:38
错误消息非常明确地表明类加载程序试图加载名为classpath*:com.attinad.model.Employee的类。
typeAliases配置应该如下所示:
<typeAliases><typeAlias type="com.attinad.model.Employee" alias="Emp"/></typeAliases>注意事项:classpath*:被移除。
sqlSessionFactory bean配置也存在同样的问题。typeAliasPackage应该如下所示:
<property name="typeAliasesPackage" value="com.attinad.model"/>https://stackoverflow.com/questions/24256165
复制相似问题