java.lang.ClassNotFoundException: javax.servlet.Filter

java.lang.ClassNotFoundException: javax.servlet.Filter:有两个原因:(1)在maven中的作用域,不能是provided,需要是compile就是默认的scope(2)spring-boot-starter-tomcat的版本bug,换个新的或旧的版本试试

 

I Started a new project with Spring Boot 1.2.3. I'm getting error

java.lang.NoClassDefFoundError: javax/servlet/Filter

Gradle Dependencies:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.codehaus.groovy:groovy")
    compile("com.h2database:h2")
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity3")

    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    testCompile("org.springframework.boot:spring-boot-starter-test")

    compile 'org.webjars:jquery:2.1.4'
    compile 'org.webjars:bootstrap:3.3.4'
}

Here is the full stack trace

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/Filter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
    at java.lang.Class.getMethod0(Class.java:2813)
    at java.lang.Class.getMethod(Class.java:1663)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:125)
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 29 more

Process finished with exit code 1

for the maven users, comment the scope provided in the following dependency:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <!--<scope>provided</scope>-->
    </dependency>

UPDATE

As feed.me mentioned you have to uncomment the provided part depending on what kind of app you are deploying.

Here is a useful link with the details: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-maven-packaging

It's important to make this dependency "provided" again before building a war file! Otherwise the war file will crash when it gets deployed (happend to me with tomcat) 

http://stackoverflow.com/questions/30374316/spring-boot-java-lang-noclassdeffounderror-javax-servlet-filter

Springboot project runs fine when running from terminal using command mvn spring-boot:run

Running from Intellij is when I was getting an exception. I changed the spring-boot-starter-tomcat in pom.xml to an older version and it runs without any exception. I think the issue was with compatibly for latest maven embed tomcat 1.2.5.RELEASE.

Now I am using below in my pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>1.2.4.RELEASE</version>
</dependency>

http://stackoverflow.com/questions/31494183/getting-a-caused-by-java-lang-noclassdeffounderror-javax-servlet-http-httpser

 

时间: 2024-10-20 23:40:19

java.lang.ClassNotFoundException: javax.servlet.Filter的相关文章

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 SpringApplicat

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 s

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z 的解决

jetty 9 嵌入式开发时,启动正常,但是页面一浏览就报错如下: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z 原因:jetty 9 依赖的servlet-api是3.X版本,如果项目中还有其它第3方开源库隐式依赖了2.x版本的servlet-api,就会报这个错.解决办法:gradle项目中,gradle dependencies 分析所有的依赖项,找出依赖低版本ser

刚学习JSF,出现java.lang.ClassNotFoundException的异常

问题描述 <?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://ja

jsp-java.lang.NoClassDefFoundError: javax/servlet/Servlet

问题描述 java.lang.NoClassDefFoundError: javax/servlet/Servlet tomcat6.0和MyEclipse发布网站服务端,总是报这个错误,百度了很多方法都没有解决掉问题,求帮助 type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. ex

tomcat6 启动报错 java.lang.NoClassDefFoundError: javax/ejb/CreateException

问题描述 win7系统+jdk1.6+myeclipse8.5启动报错代码严重:Contextinitializationfailedorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'g3ShopBoss'definedinclasspathresource[spring/spring_g3shop.xml]:Instantiationofbeanfailed;nestedexcep

java.lang.ClassNotFoundException: org.codehaus.jackson.JsonProcessingException 异常解决方案

问题: 在SpringMVC中使用Jackson实现json输出时配置如下: <!-- 输出对象转JSON支持 --> <bean id="stringConverter" class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list>

hibernate-Hibernate异常 java.lang.ClassNotFoundException

问题描述 Hibernate异常 java.lang.ClassNotFoundException 19-Oct-2015 23:24:58.329 SEVERE [http-apr-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet mvc-dispatcher java.lang.ClassNotFoundException: org.hibernat

java web-javaweb运行出java.lang.ClassNotFoundException异常

问题描述 javaweb运行出java.lang.ClassNotFoundException异常 严重: Allocate exception for servlet Web.SearchK java.lang.ClassNotFoundException: Search.searchkey at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) at org.