Mybatis,从Mapper.xml

时间:2017-09-20 10:02:02

标签: java mybatis

我正在使用MybBatis并且我在 exnternal项目中遇到 ClassNotFound 错误,并且我在 resultMap中使用该类在一个 Mapper.xml 文件中 这是我的代码:

-Mapper.xml :我只会将resultMapAquíssolocolocaréelresultMap放入,因为我遇到了问题。

<resultMap id="BaseResultMapGeneralConfig" type="classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig">
    <id column="id" jdbcType="NUMERIC" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="value" jdbcType="VARCHAR" property="value" />
    <result column="type" jdbcType="NUMERIC" property="type" />
  </resultMap>  

请注意,“type = com.etc ....”是外部项目中的类 - 我收到的错误代码:

Struts has detected an unhandled exception:

Messages:   
Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
### Error building SqlSession. ### The error may exist in com/iecisa/tecdoc/sirene/db/map/SireneConfigMapper.xml ### The error occurred while processing mapper_resultMap[BaseResultMapGeneralConfig] ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
Error inicializando SqlSession. Causa: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in com/iecisa/tecdoc/sirene/db/map/SireneConfigMapper.xml ### The error occurred while processing mapper_resultMap[BaseResultMapGeneralConfig] ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig
Error creando SqlSession: java.lang.RuntimeException: Error inicializando SqlSession. Causa: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in com/iecisa/tecdoc/sirene/db/map/SireneConfigMapper.xml ### The error occurred while processing mapper_resultMap[BaseResultMapGeneralConfig] ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig'. Cause: java.lang.ClassNotFoundException: Cannot find class: classpath:com.iecisa.tecdoc.sirene.common.types.GeneralConfig  

我已在 Java Build Path 项目标签中添加了我的主要项目中的外部项目,我还检查了外部项目检查订单和导出标签。

我尝试了不同的方法,比如没有“classpath:”这样的类,我没有找到解决方法。
任何的想法?我做错了什么? 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我得到了解决方案。问题出在项目上。我的主要项目是Maven项目,但外部不是maven。 所以我只得到外部项目的.jar,通过maven在我的主项目中添加它,并依赖于pom.xml。

这就是全部,谢谢你的帮助!