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當(dāng)使用idea開發(fā)工具時,maven作為項目管理工具時,idea是默認(rèn)不提供servlet-api.jar的,所以當(dāng)javax.servlet-api的scope的值設(shè)置provide(表示該jar在編譯時需要,而在發(fā)布時不需要)時會提示找不到對應(yīng)的jar包,我這里是提示不能創(chuàng)建對應(yīng)的service,是因為我的類中用到了HttpSession,依賴于servelt-api.jar.只需要把provide注釋掉即可。
但是,注釋掉之后,又出現(xiàn)了其他問題:如下:
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 :
創(chuàng)新互聯(lián)公司專注于彭陽企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),成都商城網(wǎng)站開發(fā)。彭陽網(wǎng)站建設(shè)公司,為彭陽等地區(qū)提供建站服務(wù)。全流程按需定制制作,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
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]
即在啟動applicationContext容器失敗。解決辦法和上面大致一樣。如下圖:
在本地啟動一個新項目時,
報錯: java.lang.ClassNotFoundException: javax.servlet.Filter
環(huán)境intellJ idea,我同事的myeclipse就可以直接啟動
最后搜了下問題
問題原因是:spring boot項目中引入使用的是scope=provided
而默認(rèn)情況下,idea是不會提供對應(yīng)的servlet-api.jar包eclipse會提供
網(wǎng)上有人說這是idea的bug,這么說顯然是不對的,是完全沒有理解provided和compile的區(qū)別
對于scope=compile的情況(默認(rèn)scope),也就是說這個項目在編譯,測試,運行階段都需要這個artifact對應(yīng)的jar包在classpath中。而對于scope=provided的情況,則可以認(rèn)為這個provided是目標(biāo)容器已經(jīng)provide這個artifact。
??????? 這么說可能不是很好理解:換個簡單的,就是你在把這個項目打成war包時,scope=provided的jar包,不會出現(xiàn)在WEB-INFO/lib目錄下,而scope=compile的jar包,會放到WEB-INFO/lib目錄
??????? 這樣可以避免想servlet-api.jar這樣的jar包沖突,但是如果遇到idea下默認(rèn)不提供servlet-api.jar時,使用scope=provided就會缺少對應(yīng)的jar包,也就是我遇到的問題找不到類
分享名稱:Causedby:java.lang.NoClassDefFoundError:
網(wǎng)站路徑:http://chinadenli.net/article4/ppssie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、標(biāo)簽優(yōu)化、做網(wǎng)站、服務(wù)器托管、關(guān)鍵詞優(yōu)化、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)