一、NoClassDefFoundError与ClassNotFoundException
  NoClassDefFoundError错误的发生,是因为Java虚拟机在编译时能找到合适的类,而在运行时不能找到合适的类导致的错误。例如在运行时我们想调用某个类的方法或者访问这个类的静态成员的时候,发现这个类不可用,此时Java虚拟机就会抛出NoClassDefFoundError错误。

  ClassNotFoundException这个错误发生只在运行时需要加载对应的类不成功,而不是编译时发生。

  NoClassDefFoundError发生在JVM在动态运行时,根据你提供的类名,在classpath中找到对应的类进行加载,但当它找不到这个类时,就发生了java.lang.NoClassDefFoundError的错误,而ClassNotFoundException是在编译的时候在classpath中找不到对应的类而发生的错误。

  简单总结就是,NoClassDefFoundError发生在编译时对应的类可用,而运行时在Java的classpath路径中,对应的类不可用导致的错误

二、NoClassDefFoundError出现的原因  

  对应的Class在java的classpath中不存在

我遇到的情况是这样的:

同一个项目中有多个模块,每个模块对应自己的pom,其中base模块导入了 spring-web的坐标,另一个spin没有导入

但是在编译的时候,spin可以找到WebApplicationContext,但是运行时就报错。

三、NoClassDefFoundError解决方法

  导入相应类(WebApplicationContext)的jar或maven坐标

 

java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext的更多相关文章

  1. Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext

    1.错误描述 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apache ...

  2. 异常:Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext

    说明项目没有加载jar包 异常:Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplic ...

  3. java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean

    昨天还好好的, 今天我的spring boot 项目就不能正常运行了! 出现: 018-07-06 10:01:41.776 WARN [mq-service,,,] 7 --- [ main] at ...

  4. SpringBoot整合nacos启动报错:java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata

    报错信息 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nacosCo ...

  5. 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener--转

    原文地址:http://www.cnblogs.com/amosli/p/4067665.html 在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.Clas ...

  6. maven 项目启动tomcat报错 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    maven项目启动tomcat报错: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLi ...

  7. ssh项目java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade错误

    错误: 导入别人的ssh项目后出现java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoade错误, 错 ...

  8. java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    参考: http://www.cnblogs.com/sunxucool/archive/2013/06/07/3124380.html   ---------------------------&g ...

  9. 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

    在使用eclipse进行整合springmvc时经常会碰到这样的异常: java.lang.ClassNotFoundException:org.springframework.web.context ...

随机推荐

  1. Mac安装HomeBridge适配小米Homekit报错:module未找到解决

    Mac安装HomeBridge适配小米Homekit报错:module未找到 具体错误是: module.js:471 throw err; balabalal...... 问了一圈,终于解决,但是又 ...

  2. 修改button样式小例子

    .toolbar button{ background: none; border:none; padding:0 3px;} <div class="toolbar toolbar- ...

  3. SSM项目开发中的实体定义以及MySQL表格设计

    话不多说,下面表格是项目开发中用到的实体集以及表格Name 实体创建     表格创建 Area 区域 Area 实体 areaId areaName priority createTime last ...

  4. Balloons

    题目链接:http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=2401 类似求连通块的问题,可以参考紫书(P162 油田),对这两个人分别执行dfs. ...

  5. Twitter开发2

    There are different API families The standard (free) Twitter APIs consist of REST APIs and Streaming ...

  6. mybatis批量更新数据参考

    https://blog.csdn.net/xyjawq1/article/details/74129316

  7. ISTQB学习笔记

    学习ISTQB大纲此文记录初次阅读时不够明确的地方 第一章:软件测试基础1. 引起软件缺陷的原因人都会犯错误(error,mistake),因此人设计的代码或文档中会引入缺陷(defect, faul ...

  8. 19. --mus-- 音乐,娱乐(词20)

  9. Git 常用使用技巧

    1.创建代码仓库 Step 1:先配置下我们的身份吧,这样在提交代码的时候Git就可以知道是谁提交的,命令如下: git config --global user.name "coder-p ...

  10. ECMAScript6语法重点(一)

    一. let和const ①let声明的变量只在它的块作用域有效({ }括起来) ②let不能重复声明同一变量 ③const声明的常量不能改(但对象可以加属性) ④const也有块作用域概念 ⑤con ...