java.lang.NoClassDefFoundError: javax/servlet/ServletContext

方法1:把SpringBoot中main方法所在的class不再继承org.springframework.boot.context.web.SpringBootServletInitializer即可

因为继承org.springframework.boot.context.web.SpringBootServletInitializer,并重写里面的configure方法,即可将这个项目打成war,并部署到tomcat或其它jee容器中。

protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {    return builder.sources(Ch623Application.class);}

方法2:

将此项目运行在一个jee容器下,譬如tomcat

2016-09-13 07:45:57.198 ERROR [main][org.springframework.boot.SpringApplication] Application startup failed
java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_65]
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_65]
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_65]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:140) ~[spring-core-4.2.0.RC1.jar:4.2.0.RC1]
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:289) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:140)    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:196) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]

    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:289)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:269) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:651) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:229)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:503) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:678) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:339) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:274) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:931) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:196)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:920) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at com.Ch623Application.main(Ch623Application.java:36) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_65]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_65]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65]
    ... 25 common frames omitted
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:269)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:651)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:503)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:678)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:339)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:274)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:931)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:920)
    at com.Ch623Application.main(Ch623Application.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 25 more
2016-09-13 07:45:57.211 INFO  [Thread-1][org.springframework.context.annotation.AnnotationConfigApplicationContext] Closing org.spring[email protected]b48321: startup date [Tue Sep 13 07:45:54 CST 2016]; root of context hierarchy
2016-09-13 07:45:57.213 WARN  [Thread-1][org.springframework.context.annotation.AnnotationConfigApplicationContext] Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call ‘refresh‘ before invoking lifecycle methods via the context: org.spring[email protected]b48321: startup date [Tue Sep 13 07:45:54 CST 2016]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:398) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:932) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:859) [spring-context-4.2.0.RC1.jar:4.2.0.RC1]
2016-09-13 07:45:57.214 DEBUG [Thread-1][org.springframework.beans.factory.support.DefaultListableBeanFactory] Destroying singletons in org.s[email protected]1fe63b9: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,ch623Application,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,authorSettings,settingsConfig,threadSettings,eventBusConfig,observer1,observer2,subject,businessService,helloJob,quartzConfig,quartzMain,scheduledTaskService,schedulerConfig,asyncTaskService,taskExecutorConfig]; root of factory hierarchy
时间: 2024-10-13 19:30:15

java.lang.NoClassDefFoundError: javax/servlet/ServletContext的相关文章

Spring boot ---- java.lang.NoClassDefFoundError: javax/servlet/ServletContext

场景描述 项目中用到spring boot进行带页面的开发,从github上的simples中下载了对应的spring-boot-sample-web-jsp项目,经简单修改之后死活启动不起来,各种异常.spring-boot以简单容易上手为核心宗旨,可为什么在引入jar时就会出现这么多问题呢? 异常信息 异常一: 2016-06-17 11:04:14.216 ERROR 4684 --- [ main] o.s.boot.SpringApplication : Application sta

如果遇到java.lang.NoClassDefFoundError: javax/servlet/ServletContext问题具体代码和解决方案如下面所示

出现的问题: java.lang.NoClassDefFoundError: javax/servlet/ServletContext at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Unknown Source) at java.lang.Class.getDeclaredMethods(Unknown Source) at org.spring

Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.linewell.wechat.WechatApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.spri

原创:idea启动项目的是否报错:java.lang.ClassNotFoundException: javax.servlet.ServletContext

在Intellij IDEA中默认所有 scope 为 provided 的依赖不会被加入到 classpath: 想想配置正确,怎么不能创建窗容器呢 ava.lang.ClassNotFoundException: javax.servlet.ServletContext 2020-03-21 17:33:17,156 WARN [org.springframework.context.support.ClassPathXmlApplicationContext] - Exception en

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

今天写SpringMvc时,遇到这样一个问题: java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config at org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java:101) at org.springframework.web.servlet.view.JstlView.exposeHelpe

Spring 4.0 StandaloneMockMvcBuilder java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig 问题解决

standaloneSetup(clrr). build(); 执行第二行 build() 时,出现下面的错误提示. java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig at org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder.initWebAppContext(StandaloneMockMvcBuilder.java:329) a

【原】tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig的解决

现象: tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig 解决: 把tomcat目录下的lib/servlet-api.jar文件拷贝到$JAVA_HOME/jre/lib/ext目录下,再启动tomcat问题解决

报错org.apache.catalina.LifecycleException caused by java.lang.NoSuchMethodError: javax.servlet.ServletContext.getClassLoader()Ljava/lang/ClassLoader

今天将tomcat6更换成了tomcat7,报错的内容 严重: A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/webandr

tomcat7 启动项目报错 java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()

JDK版本:jdk1.8.0_77 Tomcat 版本:apache-tomcat-7.0.47 异常重现步骤: 1.完成项目部署 2.启动Tomcat 异常头部信息:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig() 解决方案: 把apache-tomcat-7.0.47/lib/servlet-api.jar 拷贝到$JAVA_HOME/jre/lib/ext目录下去 参考博文: