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