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 版本不匹配,尝试比较新的版本才得以解决。

总结

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

java.lang.IllegalStateException: COMPLETED 是Java中的一个异常类型,表示当前操作在已经完成的状态下被调用,这通常是由于程序逻辑错误或者不正确的调用顺序导致的。要解决这个问题,你可以考虑以下几个方面: 1. 检查代码逻辑:首先,你需要仔细检查代码逻辑,确保在调用相关方法之前,没有提前完成或结束相关操作。这可能涉及到对方法调用顺序、条件判断和循环等进行仔细检查。 2. 检查并发操作:如果你的代码涉及到多线程或并发操作,那么可能是由于线程间的竞争条件导致了该异常。你可以考虑使用同步机制(如锁、信号量等)来保证线程安全性,或者使用并发工具类(如Atomic类、ConcurrentHashMap等)来避免竞争条件。 3. 检查资源释放:有时候,该异常可能是由于资源没有正确释放导致的。比如,在使用IO流或数据库连接时,需要确保在使用完毕后及时关闭相关资源。你可以使用try-with-resources语句或者手动关闭资源来避免该异常。 4. 查看相关文档和日志:如果以上方法都没有解决问题,你可以查看相关的文档和日志,了解该异常的具体上下文和原因。这可能需要查看相关库或框架的官方文档,或者查看程序的日志文件,以便更好地理解和解决问题。 希望以上方法能够帮助你解决 java.lang.IllegalStateException: COMPLETED 异常。如果你有任何进一步的问题,请随时提问。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值