溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Caused by: java.lang.NoClassDefFoundError:

發布時間:2020-07-22 00:08:46 來源:網絡 閱讀:2660 作者:gueryang 欄目:編程語言
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包,也就是我遇到的問題找不到類

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女