报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware

ssm的maven项目启动报错信息如下:

严重: Error configuring application listener of class com.liu.listener.InitBloggerData
java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:3118)
	at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:1340)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1827)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4984)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
	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: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextAware
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
	... 19 more
	四月 10, 2019 10:37:14 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4984)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5584)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
	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)

值摘取关键错误信息

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware

Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextAware

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

找出关键错误信息是最后一句(红色标注),分析原因,应该是没有正确加载spring的配置文件吧

1.查看web.xml

2.检查路径没有问题,

3.查看本地仓库(那是不是jar没有加载成呢)

那么明明没有问题,项目也没有报错,为啥启动tomcat会找不到该jar呢

查看tomcat(maven里的jar没有发布到tomcat的lib里)
报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware_第1张图片
原来如此,仓库里的jar根本没有添加到tomcat的lib里面

解决方法,添加maven依赖

选中项目右键-properties-输入de找到Deployment Assembly,点击add按钮
报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware_第2张图片
弹框,点击java build path entries,点击next按钮
报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware_第3张图片
点击maven dependencies,点击finish按钮
报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware_第4张图片
看已经加入了,点击apply,ok按钮
报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware_第5张图片
重新发布项目,tomcat启动成功。查看tomcat里的项目lib文件,里面已经有了所有的jar
报错找不到java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware_第6张图片

你可能感兴趣的:(java)