By default, all in scope as dependent Intellij IDEA will not be provided to the CLASSPATH added;
Think configured correctly, how it can not create a window container
ava.lang.ClassNotFoundException: javax.servlet.ServletContext
2020-03-21 17:33:17,156 WARN [org.springframework.context.support.ClassPathXmlApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.web.accept.ContentNegotiationManagerFactoryBean] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.web.accept.ContentNegotiationManagerFactoryBean] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:262) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1198) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1123) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85) at com.ibaiqi.spider.service.TestDeplication.listRecruits(TestDeplication.java:14) at com.ibaiqi.spider.service.TestDeplicationAAA.main(TestDeplicationAAA.java:31) Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.web.accept.ContentNegotiationManagerFactoryBean] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659) at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556) at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:245) ... 15 more Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.getDeclaredMethods(Class.java:1975) at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) ... 18 more Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 22 more Disconnected from the target VM, address: '127.0.0.1:52084', transport: 'socket' Process finished with exit code 1
Abnormal details:
This is a screenshot of my encounter abnormal console, as follows:
anomaly interpretation:
The default scope is provided for all the dependencies are not added to the classpath in Intellij IDEA;
so when the compiler starts spring boot project, due to a these loads can not rely on newspaper and javax.servlet.ServletContext exception.
Solution:
Method One, modify [IDEA] - Edit Configurations configuration items:
Step 1: Menu bar -> Run -> Edit Configurations
Step 2: Run / Debug Configurations -> Application -> Configuration -> check: include dependencies with "Provided" scope
second method, modified] [pom.xml configuration file:
step 1: find the picture of "spring-boot-starter-tomcat " label, there are three ways you can try;
the <scope> provided </ scope > Comment out;
<scope> tag into content provided compile: <scope> compile </ scope>;
specify the specific version of the <scope> >
; Step 2: This is the configuration on the container, the container tomcat need to reload it.
----------------
Disclaimer: This article is the original article CSDN bloggers "Tian Xiaowen", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/weixin_44259720/article/details/94602764