_宁静
2017-05-06 16:22
采纳率: 100%
浏览 1.2k
已采纳

菜鸟学SpringMVC 写第一个代码就卡主了,启动tomcat就报错,求大神们帮帮忙呀,谢谢咯~

这个是controller类代码

图片说明

这个是Applicationcontext.xml的配置

图片说明

这个是web.xml的配置

图片说明

这个 是jsp

图片说明
#这个是配置文件的位置图
图片说明
#下面是报错内容:
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [controller.HelloController] for bean with name 'hc' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: controller.HelloController
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [controller.HelloController] for bean with name 'hc' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: controller.HelloController
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5327)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5617)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [controller.HelloController] for bean with name 'hc' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: controller.HelloController
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1281)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1350)
at org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(AbstractBeanFactory.java:411)
at org.springframework.context.support.AbstractApplicationContext.isSingleton(AbstractApplicationContext.java:1137)
at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:286)
at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandlers(SimpleUrlHandlerMapping.java:129)
at org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.initApplicationContext(SimpleUrlHandlerMapping.java:104)
at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapabl
Caused by: java.lang.ClassNotFoundException: controller.HelloController
五月 06, 2017 11:42:11 下午 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet [springmvc] in web application [/com.yzl.springTest] threw load() exception
java.lang.ClassNotFoundException: controller.HelloController

代码跟教材一模一样,不知道是不是配置文件的位置放错地方了..很郁闷啊....

求大神们想想办法,没有金币咯~拜托拜托.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • _宁静 2017-05-07 17:39
    已采纳

    谢谢各位的热心回答,跟感激!!问题找到了.ide的问题, 我用的霓虹灯4.6.1版本的..我又下载了个旧的版本就ok了.!有相同问题的小伙伴们可以试试喔

    打赏 评论
  • Mature_csdn 2017-05-06 16:24

    呃 没用过 实现接口的方法 常用的都是 加注解 @Controller

    打赏 评论
  • 逻辑的奴隶 2017-05-06 17:42

    把applicationContext配置文件放到src目录下试试吧,spring找不到你配置的Controller

    打赏 评论
  • MathRandom 2017-05-07 03:02

    你把Applicationcontext.xml中的hc改成HelloController
    还有web.xml中多余的其实页面删掉试试

    打赏 评论
  • Essentail 2017-05-07 03:31

    你可以尝试自动装配,利用注解,这样手动装配容易出错。这里是说你的HandlerMapping找不到

    打赏 评论
  • 向阳m生长 2017-05-07 06:02

    在web.xml文件中是不是少了一个配置,类似这个

    org.springframework.web.context.ContextLoaderListener

    contextLoaderListener监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。

    打赏 评论
  • jasondyoung 2017-05-07 11:57

    看看id="hc"后面是否没有空格,只有换行。

    打赏 评论

相关推荐 更多相似问题