当我将 @Bean 添加到 main class 时出现 IllegalStateException

IlllegalStateException when I add @Bean to main class

当我将其添加到我的应用程序时 class

@Bean
HiddenHttpMethodFilter hiddenHttpMethodFilter() {
    return new HiddenHttpMethodFilter();
}

我的应用程序无法启动并出现此错误:

2021-11-16 08:11:08.950 ERROR 70458 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64) ~[spring-boot-2.5.6.jar:2.5.6] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.6.jar:2.5.6] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.6.jar:2.5.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.6.jar:2.5.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.6.jar:2.5.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.6.jar:2.5.6] at com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication.main(LearningSpringBootApplication.java:12) ~[main/:na] Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:162) ~[spring-core-5.3.12.jar:5.3.12] Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication

at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:403) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:326) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207) ~[spring-context-5.3.12.jar:5.3.12] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175) ~[spring-context-5.3.12.jar:5.3.12] ... 13 common frames omitted Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@22d8cfe0] Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.paulcarron.learningspringboot.learningspringboot.LearningSpringBootApplication] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@22d8cfe0]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.12.jar:5.3.12] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:455) ~[spring-core-5.3.12.jar:5.3.12] at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:151) ~[spring-core-5.3.12.jar:5.3.12] ... 18 common frames omitted Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na] Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter

at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010) ~[na:na] at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[na:na] at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na] at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010) ~[na:na] at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[na:na] at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na] at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010) ~[na:na] at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676) ~[na:na] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[na:na] at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na] at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3334) ~[na:na] at java.base/java.lang.Class.getDeclaredMethods(Class.java:2446) ~[na:na] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.12.jar:5.3.12] ... 20 common frames omitted Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter

at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[na:na] ... 51 common frames omitted

Execution failed for task ':LearningSpringBootApplication.main()'. Process 'command '/usr/local/Cellar/openjdk/16.0.1/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

What does it mean and how do I resolve it?

spring.mvc.hiddenmethod.filter.enabled=true 添加到 application.properties 以将其打开。