资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Causedby:java.lang.NoClassDefFoundError:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'identityService': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.example.new_oa.identity.service.impl.IdentityServiceImpl] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

Caused by: java.lang.NoClassDefFoundError: javax/servlet/http/HttpSession
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_181]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_181]
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_181]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) ~[spring-core-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    ... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpSession
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_181]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_181]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_181]
    ... 24 common frames omitted

当使用idea开发工具时,maven作为项目管理工具时,idea是默认不提供servlet-api.jar的,所以当javax.servlet-api的scope的值设置provide(表示该jar在编译时需要,而在发布时不需要)时会提示找不到对应的jar包,我这里是提示不能创建对应的service,是因为我的类中用到了HttpSession,依赖于servelt-api.jar.只需要把provide注释掉即可。
Caused by: java.lang.NoClassDefFoundError:
但是,注释掉之后,又出现了其他问题:如下:
Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$723b5875] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-06-29 20:05:39.786 WARN 4452 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2019-06-29 20:05:39.794 INFO 4452 --- [ main] ConditionEvaluationReportLoggingListener :

创新互联公司专注于彭阳企业网站建设,响应式网站开发,成都商城网站开发。彭阳网站建设公司,为彭阳等地区提供建站服务。全流程按需定制制作,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
Disconnected from the target VM, address: '127.0.0.1:49637', transport: 'socket'
2019-06-29 20:05:39.803 ERROR 4452 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
Caused by: java.lang.NoClassDefFoundError:
即在启动applicationContext容器失败。解决办法和上面大致一样。如下图:
Caused by: java.lang.NoClassDefFoundError:

在本地启动一个新项目时,
报错: java.lang.ClassNotFoundException: javax.servlet.Filter
环境intellJ idea,我同事的myeclipse就可以直接启动

最后搜了下问题
问题原因是:spring boot项目中引入使用的是scope=provided
而默认情况下,idea是不会提供对应的servlet-api.jar包eclipse会提供

网上有人说这是idea的bug,这么说显然是不对的,是完全没有理解provided和compile的区别
对于scope=compile的情况(默认scope),也就是说这个项目在编译,测试,运行阶段都需要这个artifact对应的jar包在classpath中。而对于scope=provided的情况,则可以认为这个provided是目标容器已经provide这个artifact。

        这么说可能不是很好理解:换个简单的,就是你在把这个项目打成war包时,scope=provided的jar包,不会出现在WEB-INFO/lib目录下,而scope=compile的jar包,会放到WEB-INFO/lib目录

        这样可以避免想servlet-api.jar这样的jar包冲突,但是如果遇到idea下默认不提供servlet-api.jar时,使用scope=provided就会缺少对应的jar包,也就是我遇到的问题找不到类


分享名称:Causedby:java.lang.NoClassDefFoundError:
网站链接:http://cdkjz.cn/article/ppssie.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220