springboot 项目启动报异常 ClassNotFoundException: javax.servlet.Filter

Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:459)
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:151)
	... 22 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter
	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:467)
	... 24 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 28 common frames omitted

IDEA配置的spring boot项目的tomcat依赖为

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-tomcatartifactId>
            <scope>providedscope>
        dependency>

provided的含义?
maven中的scope

后面试了一下,把范围标识 provided 改成 compile ,发现就可以运行了,所以就是 Run Application时,IDEA未加载 provided 范围的依赖包,导致启动时报错(eclipse里面好像默认会加载,所以在那边是能正确运行的)

解决方式 Run ->Edit Configurations
springboot 项目启动报异常 ClassNotFoundException: javax.servlet.Filter_第1张图片

参考说明:For the Spring Boot applications, the Include dependencies with “Provided” scope option is enabled by default. (按理说对于Spring-Boot项目默认是启用的,我这默认没启用所以报错)

参考

你可能感兴趣的:(异常解决,tomcat,spring)