SpringMVC 整合Mybatis 启动tomcat时报错

一点点小无奈 2015-11-25 06:26:31
现在有时间就搞了一个小的权限管理系统,以前用的是springmvc的框架,现在又加上了mybatis之后,就启动tomcat出现错误

在spring配置文件内加上这个配置就启动报错,不加就没问题:
<!-- mapper扫描器 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.popedom.mapper"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

请问各位大牛是什么原因,现在百思不得其解。报错如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userLoginMapperCustom' defined in file [F:\soft\apache-tomcat-6.0.35\webapps\popedom\WEB-INF\classes\com\popedom\mapper\UserLoginMapperCustom.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 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 'UserLoginMapperCustom'. Cause: java.lang.ClassNotFoundException: Cannot find class: UserLoginMapperCustom
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IllegalArgumentException: 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 'UserLoginMapperCustom'. Cause: java.lang.ClassNotFoundException: Cannot find class: UserLoginMapperCustom
at org.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:100)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 36 more
Caused by: 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 'UserLoginMapperCustom'. Cause: java.lang.ClassNotFoundException: Cannot find class: UserLoginMapperCustom
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)
at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.loadXmlResource(MapperAnnotationBuilder.java:164)
at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:118)
at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:71)
at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:651)
at org.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:97)
... 39 more
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserLoginMapperCustom'. Cause: java.lang.ClassNotFoundException: Cannot find class: UserLoginMapperCustom
at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:103)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:264)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:251)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:243)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)
... 45 more
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'UserLoginMapperCustom'. Cause: java.lang.ClassNotFoundException: Cannot find class: UserLoginMapperCustom
at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:117)
at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:130)
at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:101)
... 49 more
Caused by: java.lang.ClassNotFoundException: Cannot find class: UserLoginMapperCustom
at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:190)
at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
at org.apache.ibatis.io.Resources.classForName(Resources.java:256)
at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:113)
... 51 more

这是 UserLoginMapperCustom.java 接口:

package com.popedom.mapper;

import java.util.List;

import com.popedom.po.*;

public interface UserLoginMapperCustom {

public List<UserLoginCustom> findUserByUserNameAndPassword(
UsersLoginQueryVo userLoginVo);

}

这是 UserLoginMapperCustom.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.popedom.mapper.UserLoginMapperCustom">
<resultMap id="userResultMap" type="UserLoginMapperCustom">
<id column="userid" property="userid" />
<result column="username" property="username" />
<result column="userprop" property="userprop" />
<result column="propid" property="propid" />
</resultMap>

<select id="findUserByUserNameAndPassword" parameterType="com.popedom.po.UsersLoginQueryVo"
resultMap="userResultMap">
SELECT
USERID,USERNAME,USERPROP,PROPID
FROM T_ADM_USER
WHERE
USERID=#{UserLoginCustom.userid}
AND
PASSWORD=#{UserLoginCustom.password}
</select>
</mapper>


到底是个啥问题,跪求!!!!!!!!!!!!!!!!!!!!!!!
...全文
298 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Cx_轩 2015-11-30
<resultMap id="userResultMap" type="UserLoginMapperCustom"> 里面的type写全路径 加上包名啊 我的哥
回复
sdl1314520 2015-11-30
<resultMap id="userResultMap" type="UserLoginMapperCustom">这个type位置不应该是写你的实体类路劲么,怎么写的???、
回复
sdl1314520 2015-11-30
<resultMap id="userResultMap" type="UserLoginMapperCustom">UserLoginMapperCustom写全路径
回复
雷德菲尔德 2015-11-30
你看看你的sqlSessionFactory配置没有。 不是光写在MapperScannerConfigurer这个bean里,还需要你写个bean配置sqlSessionFactory,里面带链接池配置参数和xml文件扫描路径,你这个明显的ClassNotFound是没有找个这个文件映射不了
回复
ascendlin 2015-11-30
sqlSessionFactory
回复
takes2589 2015-11-28
引用 6 楼 xu_luck 的回复:
我的项目结构是这样的。
看看你的映射文件里怎么写的。
回复
ydjzj 2015-11-27
把扫描包的配置放到springmvc配置文件试试,我记得以前遇到过,要么放到spring配置文件里,要么放到mvc配置文件里。具体在哪个里面不记得了
回复
我的项目结构是这样的。
回复
引用 1 楼 chenhao237 的回复:
Mybatis根据这个别名UserLoginMapperCustom找不到相应的类
我的UserLoginMapperCustom 这个算是dao的接口类,实现dao的接口是用mybatis的xml文件来实现的。 就是老是报这个错误,请问怎么改呢 ?
回复
引用 2 楼 a1247041186 的回复:
我也遇到这个问题,楼主解决了吗
我的dao和映射文件是放在同一个包内的,都是放在:com.popedom.mappe包内的,我看网上有些放在一起,有些没有放在一起,跟这个有关系吗 ? 我怀疑是spring的问题。
回复
a1247041186 2015-11-25
我好像知道原因了 <property name="basePackage" value=""/> value指向的是Dao接口包路径 我之间指向的是映射XML包路径
回复
a1247041186 2015-11-25
我也遇到这个问题,楼主解决了吗
回复
chenhao237 2015-11-25
Mybatis根据这个别名UserLoginMapperCustom找不到相应的类
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-11-25 06:26
社区公告
暂无公告