java.lang.IllegalStateException 错误解决过程

java.lang.IllegalStateException 错误解决过程

今天在搭建 spring boot 项目的过程中出现了以下的错误,也是花了好长时间才解决,今天我就来分享一下我解决报错的过程。

2021-01-18 19:59:28.637 ERROR 19504 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Error processing condition on org.springframework.cloud.commons.httpclient.HttpClientConfiguration$ApacheHttpClientConfiguration.apacheHttpClientBuilder
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at com.liam.crowdfunding.user.CrowdfundingUserApplication.main(CrowdfundingUserApplication.java:17) [classes/:na]
Caused by: java.lang.IllegalStateException: @ConditionalOnMissingBean did not specify a bean using type, name or annotation and the attempt to deduce the bean's type failed
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.validate(OnBeanCondition.java:487) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.<init>(OnBeanCondition.java:436) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:142) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	... 18 common frames omitted
Caused by: org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanTypeDeductionException: Failed to deduce bean type for org.springframework.cloud.commons.httpclient.HttpClientConfiguration$ApacheHttpClientConfiguration.apacheHttpClientBuilder
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:517) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanType(OnBeanCondition.java:506) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.<init>(OnBeanCondition.java:429) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	... 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.client.HttpClientBuilder
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131]
	at java.lang.Class.forName0(Native Method) ~[na:1.8.0_131]
	at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_131]
	at org.springframework.boot.autoconfigure.condition.FilteringSpringBootCondition.resolve(FilteringSpringBootCondition.java:108) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.getReturnType(OnBeanCondition.java:525) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	at org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:513) ~[spring-boot-autoconfigure-2.3.8.RELEASE.jar:2.3.8.RELEASE]
	... 22 common frames omitted
  1. 百度搜索

    遇到问题就问度娘,出现了不会的问题我就马上去百度了。但是,不幸的是,百度上没有查到这种问题的解决方案,只查到一些比较类似的问题,这就比较头疼了。

  2. 分析错误

    百度找不到和我错误一致的情况,只有类似 IllegalStateException 的错误,从百度的结果来看,大致可以看出这个错误和版本冲突有关,查看官网可以发现

    public class IllegalStateException extends RuntimeException
    /*
    Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
    */
    

    表示已在非法或不适当的时间调用了方法。换句话说,对于所请求的操作,Java 环境或 Java 应用程序没有处于适当的状态,由此可以判断我的错误也应该是版本冲突的原因,通过继续阅读下面的错误提示,发现 org.springframework.cloud.commons.httpclient.HttpClientConfiguration 则有可能是相应的 jar 包版本过低(httpclient)。

  3. 尝试

    通过不断尝试,最后发现 httpclient 使用的是4.2.6版本,与我的 spring boot 版本不匹配,尝试比较新的版本才得以解决。

总结

遇到错误不可盲目相信百度,每个人都有不同的错误,只有自己通过不断的尝试和解决,才能使自己得到提升。

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页