新手求助!!!报找不到类【java.lang.ClassNotFoundException】

hqq1007 2015-09-07 02:03:24
问题描述:
在做一个springmvc+mybatis的小练习,配置文件都写好了,启动tomcat的时候报如下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.mapper.MapperScannerConfigurer#0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'markerInterface'; nested exception is java.lang.IllegalArgumentException: Cannot find class [hghan.test.springmvc.dao.MapperDao]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:548)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:116)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'markerInterface'; nested exception is java.lang.IllegalArgumentException: Cannot find class [hghan.test.springmvc.dao.MapperDao]
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:480)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:505)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1476)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1216)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
... 20 more
Caused by: java.lang.IllegalArgumentException: Cannot find class [hghan.test.springmvc.dao.MapperDao]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:282)
at org.springframework.beans.propertyeditors.ClassEditor.setAsText(ClassEditor.java:63)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:450)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:423)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:195)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:460)
... 26 more
Caused by: java.lang.ClassNotFoundException: hghan.test.springmvc.dao.MapperDao
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:246)
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:279)
... 31 more

部分配置文件如下:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${db_driverName}" />
<property name="url" value="${db_url}"/>
<property name="username" value="${db_username}" />
<property name="password" value="${db_password}" />
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="/WEB-INF/mybatis-configuration.xml" />
<property name="mapperLocations" value="classpath:hghan/test/springmvc/mapper/*.xml"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="hghan.test.springmvc" />
<property name="markerInterface" value="hghan.test.springmvc.dao.MapperDao" />
</bean>

部分代码结构图如下:


麻烦各位大神帮忙解答
【今天早上还是可以启动的,下午就突然报这个问题了,小弟找个半天也没找出原因】
...全文
1970 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
mlh1551799812 2017-12-21
我遇到的错误是:Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'markerInterface'; 解决:我的mybatis配置使用的是MapperFactoryBean,没有使用MapperScannerConfigurer,这样配置的话,需要指定具体是哪一个Dao,不能使用通配符
  • 打赏
  • 举报
回复
luohaonan365 2017-11-02
我和你报的错一样,但是问题不同,我是之前的一个jar包版本太旧,旧删除了,然后换了一个新的jar包,结果旧的jar包还在buildpath的路径里面,移除后解决
  • 打赏
  • 举报
回复
hqq1007 2015-09-07
找到问题了:原来是中午想添加一个package,但是不小心点错添加了一个Socure Folder。结果不知怎么的在.classpath中多了这么一行。 <classpathentry kind="xxx" path="xxx"/> 把这行删掉后就能够成功启动了
  • 打赏
  • 举报
回复
hqq1007 2015-09-07
引用 1 楼 andre374 的回复:
既然之前可以现在不可以,那么建议将server里该项目移除,然后重新部署,应该就好了
这个试过了,还是一样报错
  • 打赏
  • 举报
回复
andre374 2015-09-07
既然之前可以现在不可以,那么建议将server里该项目移除,然后重新部署,应该就好了
  • 打赏
  • 举报
回复
发帖
Web 开发

8.0w+

社区成员

Java Web 开发
社区管理员
  • Web 开发社区
加入社区
帖子事件
创建了帖子
2015-09-07 02:03
社区公告
暂无公告