java.lang.ClassNotFoundException springservlet

时间:2018-06-27 14:27:03

标签: java spring-mvc servlets

我正在学习有关spring mvc的教程。 我在此步骤中遇到问题:https://github.com/in28minutes/SpringMvcStepByStep/blob/master/Step11.md

我已经从链接中复制并粘贴了相同的代码(第一次根据视频键入内容,但始终会收到此错误。已经尝试了部署程序集,但未显示任何内容或其他任何东西。有人可以帮助我为什么我得到这个错误吗? m用蚀氧

Jun 27, 2018 9:19:22 PM org.apache.catalina.startup.ContextConfig getServletContainerInitializer
SEVERE: The ServletContentInitializer [org.springframework.web.SpringServletContainerInitializer] could not be created
java.lang.ClassNotFoundException: org.springframework.web.SpringServletContainerInitializer
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1668)
    at org.apache.catalina.startup.ContextConfig.getServletContainerInitializers(ContextConfig.java:1652)
    at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1562)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    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)

1 个答案:

答案 0 :(得分:1)

您的 pom.xml 应该至少是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>your-project</groupId>
    <artifactId>your-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.target>1.9</maven.compiler.target>
        <maven.compiler.source>1.9</maven.compiler.source>
    </properties>

    <dependecies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
  </dependencies>
</project>

如果需要,请用您的Spring版本替换 $ {org.springframework-version} 。如果您知道它不是 1.9 ,也请更新Java版本。您的 pom.xml 必须包括整个XML,其中<dependencies>部分至少具有 spring-webmvc 。然后运行并验证Maven是否构建了所有东西。您的项目缺少依赖项。确认您的版本设置正确。