SpringBoot启动异常:java.lang.IllegalStateException: Failed to introspect Class [xxx]

本文探讨了在项目重构过程中遇到的“Failed to introspect Class”异常,分析了该异常产生的原因,并提供了一套实用的解决方案,帮助开发者有效避免此类问题。

异常含义

  • Failed to introspect Class [xxx]
  • 内省 类xxx 失败

A类中导入了B类,但是在运行A类调用到B类地方的时候B类却找不到,这种问题本身在运行到A类中用到B类的地方是会报错的,但是这个问题比较特殊,如果A类提前被内省的时候,如果B类作为能够通过内省获取,则获取到 B类信息就会因为该类未被加载而报此错误,且提示不具体

情景

项目功能拆分过程中删除了一些类,Idea等工具暂时还没有索引到依赖的类已经不存在了或者说引入了包但是从未使用过,此时Debug项目,控制台打印内容如下:

Exception encountered during context initialization
 - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: 
 - Error creating bean with name TbCfgApi
Lookup method resolution failed; nested exception is 
java.lang.IllegalStateException: Failed to introspect Class [TbCfgCategoryAppImpl]
from ClassLoader [sun.misc.Launcher$AppClassLoader@17acb47c]

原因分析

出现这种异常的原因主要就是TbCfgCategoryAppImpl(报异常的类)中使用了当前工程没有导入的类或者是之前导入的类在整理过程中被删除,但是这个类当中仍然保留着对不存在的类的依赖,从而导致类加载失败。一般来说如果使用了没有依赖的类或者方法会报ClassNotFindException、找不到符号等错误,但是如果只是导入却没有使用的使用可能就会报此错误。

tips:像这种错误,按理来说如果打开对应的文件IDE应该会给出对应的提示,但是在一些刚整理完文件结构以及内容的时候可能会出现这种问题,像我出现问题的类,当我打开对应文件就已经出现了提示。

解决方案

  1. 检查报异常的类当中是否包含不存在的依赖(类或者包),将之导入(或者加入maven依赖),确保其对应的ClassLoader类加载器能够在当期classPath找到此类即可;如果用不到就将这条依赖删除
  2. 有时候在清理过程中光是删除使用到了不存在的类的方法不够,注意方法当中使用到了不存在的类和类的方法

特此记录,在清理不需要的类的时候,一定要注意在其他类中的装配和关联,不然容易报一些不常见的Bug

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-09-02 14:10:01.792 ERROR 23784 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at com.tplink.nbu.demo.basicspringboot.BasicSpringBootApplication.main(BasicSpringBootApplication.java:10) [classes/:na] Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:124) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:416) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:180) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] ... 8 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesReportEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1320) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:211) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:202) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:96) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:85) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:253) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:227) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5140) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_452] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_452] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_452] at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_452] at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.apache.catalina.startup.Tomcat.start(Tomcat.java:468) ~[tomcat-embed-core-9.0.34.jar:9.0.34] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:105) ~[spring-boot-2.1.14.RELEASE.jar:2.1.14.RELEASE] ... 13 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesReportEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] ... 53 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesReportEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:570) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.createEndpointBean(EndpointDiscoverer.java:141) ~[spring-boot-actuator-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.createEndpointBeans(EndpointDiscoverer.java:131) ~[spring-boot-actuator-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.discoverEndpoints(EndpointDiscoverer.java:120) ~[spring-boot-actuator-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.actuate.endpoint.annotation.EndpointDiscoverer.getEndpoints(EndpointDiscoverer.java:114) ~[spring-boot-actuator-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.servletEndpointRegistrar(ServletEndpointManagementContextConfiguration.java:72) ~[spring-boot-actuator-autoconfigure-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$5f2315ec.CGLIB$servletEndpointRegistrar$0(<generated>) ~[spring-boot-actuator-autoconfigure-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$5f2315ec$$FastClassBySpringCGLIB$$e7a46cd7.invoke(<generated>) ~[spring-boot-actuator-autoconfigure-2.1.14.RELEASE.jar:2.1.14.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration$$EnhancerBySpringCGLIB$$5f2315ec.servletEndpointRegistrar(<generated>) ~[spring-boot-actuator-autoconfigure-2.1.14.RELEASE.jar:2.1.14.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_452] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_452] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_452] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_452] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] ... 54 common frames omitted Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2] at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:760) ~[spring-core-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:692) ~[spring-core-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:423) ~[spring-orm-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:407) ~[spring-orm-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:334) ~[spring-orm-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1076) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:567) ~[spring-beans-5.1.15.RELEASE.jar:5.1.15.RELEASE] ... 75 common frames omitted Caused by: java.lang.NoClassDefFoundError: Lcom/fasterxml/jackson/databind/ObjectMapper; at java.lang.Class.getDeclaredFields0(Native Method) ~[na:1.8.0_452] at java.lang.Class.privateGetDeclaredFields(Class.java:2611) ~[na:1.8.0_452] at java.lang.Class.getDeclaredFields(Class.java:1944) ~[na:1.8.0_452] at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:755) ~[spring-core-5.1.15.RELEASE.jar:5.1.15.RELEASE] ... 81 common frames omitted Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[na:1.8.0_452] at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_452] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) ~[na:1.8.0_452] at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_452] ... 85 common frames omitted
09-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值