gpt4 book ai didi

java - spring MVC helloworld 应用程序显示 CannotLoadBeanClassException

转载 作者:行者123 更新时间:2023-11-30 11:07:30 26 4
gpt4 key购买 nike

我是 spring MVC 的新手。我正在学习以下链接中的教程: Spring Hello World

在tomcat服务器上运行应用程序出现如下异常,我猜是和controller class文件路径有关,但无法解决:

javax.servlet.ServletException: Servlet.init() for servlet SpringMVCTutorial threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
root cause

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [java.com.springmvctutorial.web.controller.HelloWorldController] for bean with name '/helloworld.htm' defined in ServletContext resource [/WEB-INF/SpringMVCTutorial-servlet.xml]; nested exception is java.lang.ClassNotFoundException: java.com.springmvctutorial.web.controller.HelloWorldController
org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1266)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:581)
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1335)
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:901)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:652)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:600)

最佳答案

您在 SpringMVCTutorial-servlet.xml 中放置了错误的类路径。使用以下路径

<bean name="/helloworld.htm"
class="com.springmvctutorial.web.controller.HelloWorldController"/>

关于java - spring MVC helloworld 应用程序显示 CannotLoadBeanClassException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28924617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com